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
7 # include <boost/type_traits/remove_cv.hpp>
8 # include <boost/mpl/bool.hpp>
9 # include <boost/detail/workaround.hpp>
11 namespace boost { namespace detail {
13 // is_incrementable<T> metafunction
15 // Requires: Given x of type T&, if the expression ++x is well-formed
16 // it must have complete type; otherwise, it must neither be ambiguous
17 // nor violate access.
19 // This namespace ensures that ADL doesn't mess things up.
20 namespace is_incrementable_
22 // a type returned from operator++ when no increment is found in the
23 // type's own namespace
26 // any soaks up implicit conversions and makes the following
27 // operator++ less-preferred than any other such operator that
28 // might be found via ADL.
29 struct any { template <class T> any(T const&); };
31 // This is a last-resort operator++ for when none other is found
32 tag operator++(any const&);
33 tag operator++(any const&,int);
35 # if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3202)) \
36 || BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
37 # define BOOST_comma(a,b) (a)
39 // In case an operator++ is found that returns void, we'll use ++x,0
40 tag operator,(tag,int);
41 # define BOOST_comma(a,b) (a,b)
44 // two check overloads help us identify which operator++ was picked
45 char (& check(tag) )[2];
54 static typename remove_cv<T>::type& x;
56 BOOST_STATIC_CONSTANT(
58 , value = sizeof(is_incrementable_::check(BOOST_comma(++x,0))) == 1
65 static typename remove_cv<T>::type& x;
67 BOOST_STATIC_CONSTANT(
69 , value = sizeof(is_incrementable_::check(BOOST_comma(x++,0))) == 1
77 struct is_incrementable
78 : mpl::bool_< ::boost::detail::is_incrementable_::impl<T>::value>
83 struct is_postfix_incrementable
84 : mpl::bool_< ::boost::detail::is_incrementable_::postfix_impl<T>::value>
88 }} // namespace boost::detail
90 #endif // IS_INCREMENTABLE_DWA200415_HPP