Bug fix.
2 * lemon/utility.h - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi
5 * Kutatocsoport (Egervary Research Group on Combinatorial Optimization,
8 * Permission to use, modify and distribute this software is granted
9 * provided that this copyright notice appears in all copies. For
10 * precise terms see the accompanying LICENSE file.
12 * This software is provided "AS IS" with no warranty of any kind,
13 * express or implied, and with no claim as to its suitability for any
16 * This file contains a modified version of the enable_if library from BOOST.
17 * See the appropriate copyright notice below.
20 // Boost enable_if library
22 // Copyright 2003 © The Trustees of Indiana University.
24 // Use, modification, and distribution is subject to the Boost Software
25 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
26 // http://www.boost.org/LICENSE_1_0.txt)
28 // Authors: Jaakko Järvi (jajarvi at osl.iu.edu)
29 // Jeremiah Willcock (jewillco at osl.iu.edu)
30 // Andrew Lumsdaine (lums at osl.iu.edu)
33 #ifndef LEMON_UTILITY_H
34 #define LEMON_UTILITY_H
37 ///\brief Miscellaneous basic utilities
39 ///\todo Please rethink the organisation of the basic files like this.
40 ///E.g. this file might be merged with invalid.h.
46 /// Basic type for defining "tags". A "YES" condition for \c enable_if.
48 /// Basic type for defining "tags". A "YES" condition for \c enable_if.
52 /// \todo This should go to a separate "basic_types.h" (or something)
56 static const bool value = true;
59 /// Basic type for defining "tags". A "NO" condition for \c enable_if.
61 /// Basic type for defining "tags". A "NO" condition for \c enable_if.
66 static const bool value = false;
72 Wrap(const T &t) : value(t) {}
75 /**************** dummy class to avoid ambiguity ****************/
77 template<int T> struct dummy { dummy(int) {} };
79 /**************** enable_if from BOOST ****************/
81 template <bool B, class T = void>
87 struct enable_if_c<false, T> {};
89 template <class Cond, class T = void>
90 struct enable_if : public enable_if_c<Cond::value, T> {};
92 template <bool B, class T>
93 struct lazy_enable_if_c {
94 typedef typename T::type type;
98 struct lazy_enable_if_c<false, T> {};
100 template <class Cond, class T>
101 struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {};
104 template <bool B, class T = void>
105 struct disable_if_c {
110 struct disable_if_c<true, T> {};
112 template <class Cond, class T = void>
113 struct disable_if : public disable_if_c<Cond::value, T> {};
115 template <bool B, class T>
116 struct lazy_disable_if_c {
117 typedef typename T::type type;
121 struct lazy_disable_if_c<true, T> {};
123 template <class Cond, class T>
124 struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {};
128 template <typename _Type, typename Enable = void>
129 struct SmartReference {
133 template <typename _Type>
134 struct SmartReference<
136 typename enable_if<typename _Type::NeedCopy, void>::type
141 template <typename _Type, typename Enable = void>
142 struct SmartConstReference {
143 typedef const _Type& Type;
146 template <typename _Type>
147 struct SmartConstReference<
149 typename enable_if<typename _Type::NeedCopy, void>::type
151 typedef const _Type Type;
154 template <typename _Type, typename Enable = void>
155 struct SmartParameter {
159 template <typename _Type>
160 struct SmartParameter<
162 typename enable_if<typename _Type::NeedCopy, void>::type
164 typedef const _Type& Type;