[220] | 1 | /* -*- mode: C++; indent-tabs-mode: nil; -*- |
---|
| 2 | * |
---|
| 3 | * This file is a part of LEMON, a generic C++ optimization library. |
---|
| 4 | * |
---|
[440] | 5 | * Copyright (C) 2003-2009 |
---|
[220] | 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
| 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
| 8 | * |
---|
| 9 | * Permission to use, modify and distribute this software is granted |
---|
| 10 | * provided that this copyright notice appears in all copies. For |
---|
| 11 | * precise terms see the accompanying LICENSE file. |
---|
| 12 | * |
---|
| 13 | * This software is provided "AS IS" with no warranty of any kind, |
---|
| 14 | * express or implied, and with no claim as to its suitability for any |
---|
| 15 | * purpose. |
---|
| 16 | * |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | // This file contains a modified version of the enable_if library from BOOST. |
---|
| 20 | // See the appropriate copyright notice below. |
---|
| 21 | |
---|
| 22 | // Boost enable_if library |
---|
| 23 | |
---|
| 24 | // Copyright 2003 (c) The Trustees of Indiana University. |
---|
| 25 | |
---|
| 26 | // Use, modification, and distribution is subject to the Boost Software |
---|
| 27 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
---|
| 28 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
| 29 | |
---|
| 30 | // Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) |
---|
| 31 | // Jeremiah Willcock (jewillco at osl.iu.edu) |
---|
| 32 | // Andrew Lumsdaine (lums at osl.iu.edu) |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | #ifndef LEMON_BITS_ENABLE_IF_H |
---|
| 36 | #define LEMON_BITS_ENABLE_IF_H |
---|
| 37 | |
---|
[314] | 38 | //\file |
---|
| 39 | //\brief Miscellaneous basic utilities |
---|
[220] | 40 | |
---|
| 41 | namespace lemon |
---|
| 42 | { |
---|
| 43 | |
---|
[314] | 44 | // Basic type for defining "tags". A "YES" condition for \c enable_if. |
---|
[220] | 45 | |
---|
[314] | 46 | // Basic type for defining "tags". A "YES" condition for \c enable_if. |
---|
| 47 | // |
---|
| 48 | //\sa False |
---|
[220] | 49 | struct True { |
---|
[314] | 50 | //\e |
---|
[220] | 51 | static const bool value = true; |
---|
| 52 | }; |
---|
| 53 | |
---|
[314] | 54 | // Basic type for defining "tags". A "NO" condition for \c enable_if. |
---|
[220] | 55 | |
---|
[314] | 56 | // Basic type for defining "tags". A "NO" condition for \c enable_if. |
---|
| 57 | // |
---|
| 58 | //\sa True |
---|
[220] | 59 | struct False { |
---|
[314] | 60 | //\e |
---|
[220] | 61 | static const bool value = false; |
---|
| 62 | }; |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | template <typename T> |
---|
| 67 | struct Wrap { |
---|
| 68 | const T &value; |
---|
| 69 | Wrap(const T &t) : value(t) {} |
---|
| 70 | }; |
---|
| 71 | |
---|
| 72 | /**************** dummy class to avoid ambiguity ****************/ |
---|
| 73 | |
---|
| 74 | template<int T> struct dummy { dummy(int) {} }; |
---|
| 75 | |
---|
| 76 | /**************** enable_if from BOOST ****************/ |
---|
| 77 | |
---|
| 78 | template <typename Type, typename T = void> |
---|
| 79 | struct exists { |
---|
| 80 | typedef T type; |
---|
| 81 | }; |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | template <bool B, class T = void> |
---|
| 85 | struct enable_if_c { |
---|
| 86 | typedef T type; |
---|
| 87 | }; |
---|
| 88 | |
---|
| 89 | template <class T> |
---|
| 90 | struct enable_if_c<false, T> {}; |
---|
| 91 | |
---|
| 92 | template <class Cond, class T = void> |
---|
| 93 | struct enable_if : public enable_if_c<Cond::value, T> {}; |
---|
| 94 | |
---|
| 95 | template <bool B, class T> |
---|
| 96 | struct lazy_enable_if_c { |
---|
| 97 | typedef typename T::type type; |
---|
| 98 | }; |
---|
| 99 | |
---|
| 100 | template <class T> |
---|
| 101 | struct lazy_enable_if_c<false, T> {}; |
---|
| 102 | |
---|
| 103 | template <class Cond, class T> |
---|
| 104 | struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {}; |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | template <bool B, class T = void> |
---|
| 108 | struct disable_if_c { |
---|
| 109 | typedef T type; |
---|
| 110 | }; |
---|
| 111 | |
---|
| 112 | template <class T> |
---|
| 113 | struct disable_if_c<true, T> {}; |
---|
| 114 | |
---|
| 115 | template <class Cond, class T = void> |
---|
| 116 | struct disable_if : public disable_if_c<Cond::value, T> {}; |
---|
| 117 | |
---|
| 118 | template <bool B, class T> |
---|
| 119 | struct lazy_disable_if_c { |
---|
| 120 | typedef typename T::type type; |
---|
| 121 | }; |
---|
| 122 | |
---|
| 123 | template <class T> |
---|
| 124 | struct lazy_disable_if_c<true, T> {}; |
---|
| 125 | |
---|
| 126 | template <class Cond, class T> |
---|
| 127 | struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {}; |
---|
| 128 | |
---|
| 129 | } // namespace lemon |
---|
| 130 | |
---|
| 131 | #endif |
---|