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