| 1 | ////////////////////////////////////////////////////////////////////////////// |
| 2 | // |
| 3 | // (C) Copyright Ion Gaztanaga 2015-2015. |
| 4 | // Distributed under the Boost Software License, Version 1.0. |
| 5 | // (See accompanying file LICENSE_1_0.txt or copy at |
| 6 | // http://www.boost.org/LICENSE_1_0.txt) |
| 7 | // |
| 8 | // See http://www.boost.org/libs/move for documentation. |
| 9 | // |
| 10 | ////////////////////////////////////////////////////////////////////////////// |
| 11 | |
| 12 | //! \file |
| 13 | |
| 14 | #ifndef BOOST_MOVE_DETAIL_META_UTILS_CORE_HPP |
| 15 | #define BOOST_MOVE_DETAIL_META_UTILS_CORE_HPP |
| 16 | |
| 17 | #ifndef BOOST_CONFIG_HPP |
| 18 | # include <boost/config.hpp> |
| 19 | #endif |
| 20 | # |
| 21 | #if defined(BOOST_HAS_PRAGMA_ONCE) |
| 22 | # pragma once |
| 23 | #endif |
| 24 | |
| 25 | //Small meta-typetraits to support move |
| 26 | |
| 27 | namespace boost { |
| 28 | namespace move_detail { |
| 29 | |
| 30 | template<typename T> |
| 31 | struct voider { typedef void type; }; |
| 32 | |
| 33 | ////////////////////////////////////// |
| 34 | // if_c |
| 35 | ////////////////////////////////////// |
| 36 | template<bool C, typename T1, typename T2> |
| 37 | struct if_c |
| 38 | { |
| 39 | typedef T1 type; |
| 40 | }; |
| 41 | |
| 42 | template<typename T1, typename T2> |
| 43 | struct if_c<false,T1,T2> |
| 44 | { |
| 45 | typedef T2 type; |
| 46 | }; |
| 47 | |
| 48 | ////////////////////////////////////// |
| 49 | // if_ |
| 50 | ////////////////////////////////////// |
| 51 | template<typename T1, typename T2, typename T3> |
| 52 | struct if_ : if_c<0 != T1::value, T2, T3> |
| 53 | {}; |
| 54 | |
| 55 | ////////////////////////////////////// |
| 56 | // enable_if_c |
| 57 | ////////////////////////////////////// |
| 58 | struct enable_if_nat{}; |
| 59 | |
| 60 | template <bool B, class T = enable_if_nat> |
| 61 | struct enable_if_c |
| 62 | { |
| 63 | typedef T type; |
| 64 | }; |
| 65 | |
| 66 | template <class T> |
| 67 | struct enable_if_c<false, T> {}; |
| 68 | |
| 69 | ////////////////////////////////////// |
| 70 | // enable_if |
| 71 | ////////////////////////////////////// |
| 72 | template <class Cond, class T = enable_if_nat> |
| 73 | struct enable_if : enable_if_c<Cond::value, T> {}; |
| 74 | |
| 75 | ////////////////////////////////////// |
| 76 | // disable_if_c |
| 77 | ////////////////////////////////////// |
| 78 | template <bool B, class T = enable_if_nat> |
| 79 | struct disable_if_c |
| 80 | : enable_if_c<!B, T> |
| 81 | {}; |
| 82 | |
| 83 | ////////////////////////////////////// |
| 84 | // disable_if |
| 85 | ////////////////////////////////////// |
| 86 | template <class Cond, class T = enable_if_nat> |
| 87 | struct disable_if : enable_if_c<!Cond::value, T> {}; |
| 88 | |
| 89 | ////////////////////////////////////// |
| 90 | // integral_constant |
| 91 | ////////////////////////////////////// |
| 92 | template<class T, T v> |
| 93 | struct integral_constant |
| 94 | { |
| 95 | static const T value = v; |
| 96 | typedef T value_type; |
| 97 | typedef integral_constant<T, v> type; |
| 98 | |
| 99 | operator T() const { return value; } |
| 100 | T operator()() const { return value; } |
| 101 | }; |
| 102 | |
| 103 | typedef integral_constant<bool, true > true_type; |
| 104 | typedef integral_constant<bool, false > false_type; |
| 105 | |
| 106 | |
| 107 | ////////////////////////////////////// |
| 108 | // is_same |
| 109 | ////////////////////////////////////// |
| 110 | template<class T, class U> |
| 111 | struct is_same |
| 112 | { |
| 113 | static const bool value = false; |
| 114 | }; |
| 115 | |
| 116 | template<class T> |
| 117 | struct is_same<T, T> |
| 118 | { |
| 119 | static const bool value = true; |
| 120 | }; |
| 121 | |
| 122 | ////////////////////////////////////// |
| 123 | // enable_if_same |
| 124 | ////////////////////////////////////// |
| 125 | template <class T, class U, class R = enable_if_nat> |
| 126 | struct enable_if_same : enable_if<is_same<T, U>, R> {}; |
| 127 | |
| 128 | ////////////////////////////////////// |
| 129 | // disable_if_same |
| 130 | ////////////////////////////////////// |
| 131 | template <class T, class U, class R = enable_if_nat> |
| 132 | struct disable_if_same : disable_if<is_same<T, U>, R> {}; |
| 133 | |
| 134 | } //namespace move_detail { |
| 135 | } //namespace boost { |
| 136 | |
| 137 | #endif //#ifndef BOOST_MOVE_DETAIL_META_UTILS_CORE_HPP |
| 138 | |