Avoid ambiguity.
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 enable_if.
48 /// \todo This should go to a separate "basic_types.h" (or something)
51 static const bool value = true;
54 /// Basic type for defining "tags". A "NO" condition for enable_if.
56 static const bool value = false;
62 Wrap(const T &t) : value(t) {}
65 /**************** dummy class to avoid ambiguity ****************/
67 template<int T> struct dummy { dummy(int) {} };
69 /**************** enable_if from BOOST ****************/
71 template <bool B, class T = void>
77 struct enable_if_c<false, T> {};
79 template <class Cond, class T = void>
80 struct enable_if : public enable_if_c<Cond::value, T> {};
82 template <bool B, class T>
83 struct lazy_enable_if_c {
84 typedef typename T::type type;
88 struct lazy_enable_if_c<false, T> {};
90 template <class Cond, class T>
91 struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {};
94 template <bool B, class T = void>
100 struct disable_if_c<true, T> {};
102 template <class Cond, class T = void>
103 struct disable_if : public disable_if_c<Cond::value, T> {};
105 template <bool B, class T>
106 struct lazy_disable_if_c {
107 typedef typename T::type type;
111 struct lazy_disable_if_c<true, T> {};
113 template <class Cond, class T>
114 struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {};
118 template <typename _Type, typename Enable = void>
119 struct SmartReference {
123 template <typename _Type>
124 struct SmartReference<
126 typename enable_if<typename _Type::NeedCopy, void>::type
131 template <typename _Type, typename Enable = void>
132 struct SmartConstReference {
133 typedef const _Type& Type;
136 template <typename _Type>
137 struct SmartConstReference<
139 typename enable_if<typename _Type::NeedCopy, void>::type
141 typedef const _Type Type;
144 template <typename _Type, typename Enable = void>
145 struct SmartParameter {
149 template <typename _Type>
150 struct SmartParameter<
152 typename enable_if<typename _Type::NeedCopy, void>::type
154 typedef const _Type& Type;