1 | /* -*- C++ -*- |
---|
2 | * |
---|
3 | * src/lemon/utility.h - Part of LEMON, a generic C++ optimization library |
---|
4 | * |
---|
5 | * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi |
---|
6 | * Kutatocsoport (Egervary Research Group on Combinatorial Optimization, |
---|
7 | * 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 | * This file contains a modified version of the enable_if library from BOOST. |
---|
18 | * See the appropriate copyright notice below. |
---|
19 | */ |
---|
20 | |
---|
21 | // Boost enable_if library |
---|
22 | |
---|
23 | // Copyright 2003 © The Trustees of Indiana University. |
---|
24 | |
---|
25 | // Use, modification, and distribution is subject to the Boost Software |
---|
26 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
---|
27 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
28 | |
---|
29 | // Authors: Jaakko Järvi (jajarvi at osl.iu.edu) |
---|
30 | // Jeremiah Willcock (jewillco at osl.iu.edu) |
---|
31 | // Andrew Lumsdaine (lums at osl.iu.edu) |
---|
32 | |
---|
33 | |
---|
34 | #ifndef LEMON_UTILITY_H |
---|
35 | #define LEMON_UTILITY_H |
---|
36 | |
---|
37 | namespace lemon |
---|
38 | { |
---|
39 | |
---|
40 | /// Basic type for defining "tags". A "YES" condition for enable_if. |
---|
41 | |
---|
42 | /// \todo This should go to a separate "basic_types.h" (or something) |
---|
43 | /// file. |
---|
44 | struct True { |
---|
45 | static const bool value = true; |
---|
46 | }; |
---|
47 | |
---|
48 | /// Basic type for defining "tags". A "NO" condition for enable_if. |
---|
49 | struct False { |
---|
50 | static const bool value = false; |
---|
51 | }; |
---|
52 | |
---|
53 | template <typename T> |
---|
54 | struct Wrap { |
---|
55 | const T &value; |
---|
56 | Wrap(const T &t) : value(t) {} |
---|
57 | }; |
---|
58 | |
---|
59 | /**************** dummy class to avoid ambiguity ****************/ |
---|
60 | |
---|
61 | template<int T> struct dummy { dummy(int) {} }; |
---|
62 | |
---|
63 | /**************** enable_if from BOOST ****************/ |
---|
64 | |
---|
65 | template <bool B, class T = void> |
---|
66 | struct enable_if_c { |
---|
67 | typedef T type; |
---|
68 | }; |
---|
69 | |
---|
70 | template <class T> |
---|
71 | struct enable_if_c<false, T> {}; |
---|
72 | |
---|
73 | template <class Cond, class T = void> |
---|
74 | struct enable_if : public enable_if_c<Cond::value, T> {}; |
---|
75 | |
---|
76 | template <bool B, class T> |
---|
77 | struct lazy_enable_if_c { |
---|
78 | typedef typename T::type type; |
---|
79 | }; |
---|
80 | |
---|
81 | template <class T> |
---|
82 | struct lazy_enable_if_c<false, T> {}; |
---|
83 | |
---|
84 | template <class Cond, class T> |
---|
85 | struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {}; |
---|
86 | |
---|
87 | |
---|
88 | template <bool B, class T = void> |
---|
89 | struct disable_if_c { |
---|
90 | typedef T type; |
---|
91 | }; |
---|
92 | |
---|
93 | template <class T> |
---|
94 | struct disable_if_c<true, T> {}; |
---|
95 | |
---|
96 | template <class Cond, class T = void> |
---|
97 | struct disable_if : public disable_if_c<Cond::value, T> {}; |
---|
98 | |
---|
99 | template <bool B, class T> |
---|
100 | struct lazy_disable_if_c { |
---|
101 | typedef typename T::type type; |
---|
102 | }; |
---|
103 | |
---|
104 | template <class T> |
---|
105 | struct lazy_disable_if_c<true, T> {}; |
---|
106 | |
---|
107 | template <class Cond, class T> |
---|
108 | struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {}; |
---|
109 | |
---|
110 | } // namespace lemon |
---|
111 | |
---|
112 | #endif |
---|