Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 1 | // Copyright David Abrahams 2004. Use, modification and distribution is |
| 2 | // subject to the Boost Software License, Version 1.0. (See accompanying |
| 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 4 | #ifndef IS_INCREMENTABLE_DWA200415_HPP |
| 5 | # define IS_INCREMENTABLE_DWA200415_HPP |
| 6 | |
| 7 | # include <ndnboost/type_traits/detail/template_arity_spec.hpp> |
| 8 | # include <ndnboost/type_traits/remove_cv.hpp> |
| 9 | # include <ndnboost/mpl/aux_/lambda_support.hpp> |
| 10 | # include <ndnboost/mpl/bool.hpp> |
| 11 | # include <ndnboost/detail/workaround.hpp> |
| 12 | |
| 13 | // Must be the last include |
| 14 | # include <ndnboost/type_traits/detail/bool_trait_def.hpp> |
| 15 | |
| 16 | namespace ndnboost { namespace detail { |
| 17 | |
| 18 | // is_incrementable<T> metafunction |
| 19 | // |
| 20 | // Requires: Given x of type T&, if the expression ++x is well-formed |
| 21 | // it must have complete type; otherwise, it must neither be ambiguous |
| 22 | // nor violate access. |
| 23 | |
| 24 | // This namespace ensures that ADL doesn't mess things up. |
| 25 | namespace is_incrementable_ |
| 26 | { |
| 27 | // a type returned from operator++ when no increment is found in the |
| 28 | // type's own namespace |
| 29 | struct tag {}; |
| 30 | |
| 31 | // any soaks up implicit conversions and makes the following |
| 32 | // operator++ less-preferred than any other such operator that |
| 33 | // might be found via ADL. |
| 34 | struct any { template <class T> any(T const&); }; |
| 35 | |
| 36 | // This is a last-resort operator++ for when none other is found |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 37 | # if NDNBOOST_WORKAROUND(__GNUC__, == 4) && __GNUC_MINOR__ == 0 && __GNUC_PATCHLEVEL__ == 2 |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 38 | |
| 39 | } |
| 40 | |
| 41 | namespace is_incrementable_2 |
| 42 | { |
| 43 | is_incrementable_::tag operator++(is_incrementable_::any const&); |
| 44 | is_incrementable_::tag operator++(is_incrementable_::any const&,int); |
| 45 | } |
| 46 | using namespace is_incrementable_2; |
| 47 | |
| 48 | namespace is_incrementable_ |
| 49 | { |
| 50 | |
| 51 | # else |
| 52 | |
| 53 | tag operator++(any const&); |
| 54 | tag operator++(any const&,int); |
| 55 | |
| 56 | # endif |
| 57 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 58 | # if NDNBOOST_WORKAROUND(__MWERKS__, NDNBOOST_TESTED_AT(0x3202)) \ |
| 59 | || NDNBOOST_WORKAROUND(NDNBOOST_MSVC, <= 1300) |
| 60 | # define NDNBOOST_comma(a,b) (a) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 61 | # else |
| 62 | // In case an operator++ is found that returns void, we'll use ++x,0 |
| 63 | tag operator,(tag,int); |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 64 | # define NDNBOOST_comma(a,b) (a,b) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 65 | # endif |
| 66 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 67 | # if defined(NDNBOOST_MSVC) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 68 | # pragma warning(push) |
| 69 | # pragma warning(disable:4913) // Warning about operator, |
| 70 | # endif |
| 71 | |
| 72 | // two check overloads help us identify which operator++ was picked |
| 73 | char (& check_(tag) )[2]; |
| 74 | |
| 75 | template <class T> |
| 76 | char check_(T const&); |
| 77 | |
| 78 | |
| 79 | template <class T> |
| 80 | struct impl |
| 81 | { |
| 82 | static typename ndnboost::remove_cv<T>::type& x; |
| 83 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 84 | NDNBOOST_STATIC_CONSTANT( |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 85 | bool |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 86 | , value = sizeof(is_incrementable_::check_(NDNBOOST_comma(++x,0))) == 1 |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 87 | ); |
| 88 | }; |
| 89 | |
| 90 | template <class T> |
| 91 | struct postfix_impl |
| 92 | { |
| 93 | static typename ndnboost::remove_cv<T>::type& x; |
| 94 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 95 | NDNBOOST_STATIC_CONSTANT( |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 96 | bool |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 97 | , value = sizeof(is_incrementable_::check_(NDNBOOST_comma(x++,0))) == 1 |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 98 | ); |
| 99 | }; |
| 100 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 101 | # if defined(NDNBOOST_MSVC) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 102 | # pragma warning(pop) |
| 103 | # endif |
| 104 | |
| 105 | } |
| 106 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 107 | # undef NDNBOOST_comma |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 108 | |
| 109 | template<typename T> |
| 110 | struct is_incrementable |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 111 | NDNBOOST_TT_AUX_BOOL_C_BASE(::ndnboost::detail::is_incrementable_::impl<T>::value) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 112 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 113 | NDNBOOST_TT_AUX_BOOL_TRAIT_VALUE_DECL(::ndnboost::detail::is_incrementable_::impl<T>::value) |
| 114 | NDNBOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_incrementable,(T)) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | template<typename T> |
| 118 | struct is_postfix_incrementable |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 119 | NDNBOOST_TT_AUX_BOOL_C_BASE(::ndnboost::detail::is_incrementable_::impl<T>::value) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 120 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 121 | NDNBOOST_TT_AUX_BOOL_TRAIT_VALUE_DECL(::ndnboost::detail::is_incrementable_::postfix_impl<T>::value) |
| 122 | NDNBOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_postfix_incrementable,(T)) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | } // namespace detail |
| 126 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 127 | NDNBOOST_TT_AUX_TEMPLATE_ARITY_SPEC(1, ::ndnboost::detail::is_incrementable) |
| 128 | NDNBOOST_TT_AUX_TEMPLATE_ARITY_SPEC(1, ::ndnboost::detail::is_postfix_incrementable) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 129 | |
| 130 | } // namespace ndnboost |
| 131 | |
| 132 | # include <ndnboost/type_traits/detail/bool_trait_undef.hpp> |
| 133 | |
| 134 | #endif // IS_INCREMENTABLE_DWA200415_HPP |