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