williamr@2: // Copyright David Abrahams 2004. Use, modification and distribution is
williamr@2: // subject to the Boost Software License, Version 1.0. (See accompanying
williamr@2: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
williamr@2: #ifndef IS_INCREMENTABLE_DWA200415_HPP
williamr@2: # define IS_INCREMENTABLE_DWA200415_HPP
williamr@2: 
williamr@2: # include <boost/type_traits/detail/template_arity_spec.hpp>
williamr@2: # include <boost/type_traits/remove_cv.hpp>
williamr@2: # include <boost/mpl/aux_/lambda_support.hpp>
williamr@2: # include <boost/mpl/bool.hpp>
williamr@2: # include <boost/detail/workaround.hpp>
williamr@2: 
williamr@2: // Must be the last include
williamr@2: # include <boost/type_traits/detail/bool_trait_def.hpp>
williamr@2: 
williamr@2: namespace boost { namespace detail { 
williamr@2: 
williamr@2: // is_incrementable<T> metafunction
williamr@2: //
williamr@2: // Requires: Given x of type T&, if the expression ++x is well-formed
williamr@2: // it must have complete type; otherwise, it must neither be ambiguous
williamr@2: // nor violate access.
williamr@2: 
williamr@2: // This namespace ensures that ADL doesn't mess things up.
williamr@2: namespace is_incrementable_
williamr@2: {
williamr@2:   // a type returned from operator++ when no increment is found in the
williamr@2:   // type's own namespace
williamr@2:   struct tag {};
williamr@2:   
williamr@2:   // any soaks up implicit conversions and makes the following
williamr@2:   // operator++ less-preferred than any other such operator that
williamr@2:   // might be found via ADL.
williamr@2:   struct any { template <class T> any(T const&); };
williamr@2: 
williamr@2:   // This is a last-resort operator++ for when none other is found
williamr@2: # if BOOST_WORKAROUND(__GNUC__, == 4) && __GNUC_MINOR__ == 0 && __GNUC_PATCHLEVEL__ == 2
williamr@2:   
williamr@2: }
williamr@2: 
williamr@2: namespace is_incrementable_2
williamr@2: {
williamr@2:   is_incrementable_::tag operator++(is_incrementable_::any const&);
williamr@2:   is_incrementable_::tag operator++(is_incrementable_::any const&,int);
williamr@2: }
williamr@2: using namespace is_incrementable_2;
williamr@2: 
williamr@2: namespace is_incrementable_
williamr@2: {
williamr@2:   
williamr@2: # else
williamr@2:   
williamr@2:   tag operator++(any const&);
williamr@2:   tag operator++(any const&,int);
williamr@2:   
williamr@2: # endif 
williamr@2: 
williamr@2: # if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3202)) \
williamr@2:     || BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
williamr@2: #  define BOOST_comma(a,b) (a)
williamr@2: # else 
williamr@2:   // In case an operator++ is found that returns void, we'll use ++x,0
williamr@2:   tag operator,(tag,int);  
williamr@2: #  define BOOST_comma(a,b) (a,b)
williamr@2: # endif 
williamr@2:   
williamr@2:   // two check overloads help us identify which operator++ was picked
williamr@2:   char (& check(tag) )[2];
williamr@2:   
williamr@2:   template <class T>
williamr@2:   char check(T const&);
williamr@2:   
williamr@2: 
williamr@2:   template <class T>
williamr@2:   struct impl
williamr@2:   {
williamr@2:       static typename boost::remove_cv<T>::type& x;
williamr@2: 
williamr@2:       BOOST_STATIC_CONSTANT(
williamr@2:           bool
williamr@2:         , value = sizeof(is_incrementable_::check(BOOST_comma(++x,0))) == 1
williamr@2:       );
williamr@2:   };
williamr@2: 
williamr@2:   template <class T>
williamr@2:   struct postfix_impl
williamr@2:   {
williamr@2:       static typename boost::remove_cv<T>::type& x;
williamr@2: 
williamr@2:       BOOST_STATIC_CONSTANT(
williamr@2:           bool
williamr@2:         , value = sizeof(is_incrementable_::check(BOOST_comma(x++,0))) == 1
williamr@2:       );
williamr@2:   };
williamr@2: }
williamr@2: 
williamr@2: # undef BOOST_comma
williamr@2: 
williamr@2: template<typename T> 
williamr@2: struct is_incrementable 
williamr@2: BOOST_TT_AUX_BOOL_C_BASE(::boost::detail::is_incrementable_::impl<T>::value)
williamr@2: { 
williamr@2:     BOOST_TT_AUX_BOOL_TRAIT_VALUE_DECL(::boost::detail::is_incrementable_::impl<T>::value)
williamr@2:     BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_incrementable,(T))
williamr@2: };
williamr@2: 
williamr@2: template<typename T> 
williamr@2: struct is_postfix_incrementable 
williamr@2: BOOST_TT_AUX_BOOL_C_BASE(::boost::detail::is_incrementable_::impl<T>::value)
williamr@2: { 
williamr@2:     BOOST_TT_AUX_BOOL_TRAIT_VALUE_DECL(::boost::detail::is_incrementable_::postfix_impl<T>::value)
williamr@2:     BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_postfix_incrementable,(T))
williamr@2: };
williamr@2: 
williamr@2: } // namespace detail
williamr@2: 
williamr@2: BOOST_TT_AUX_TEMPLATE_ARITY_SPEC(1, ::boost::detail::is_incrementable)
williamr@2: BOOST_TT_AUX_TEMPLATE_ARITY_SPEC(1, ::boost::detail::is_postfix_incrementable)
williamr@2: 
williamr@2: } // namespace boost
williamr@2: 
williamr@2: # include <boost/type_traits/detail/bool_trait_undef.hpp>
williamr@2: 
williamr@2: #endif // IS_INCREMENTABLE_DWA200415_HPP