]> git.lyx.org Git - lyx.git/blob - boost/boost/detail/is_incrementable.hpp
update to boost 1.32.0
[lyx.git] / boost / boost / detail / is_incrementable.hpp
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 <boost/type_traits/remove_cv.hpp>
8 # include <boost/mpl/bool.hpp>
9 # include <boost/detail/workaround.hpp>
10
11 namespace boost { namespace detail { 
12
13 // is_incrementable<T> metafunction
14 //
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.
18
19 // This namespace ensures that ADL doesn't mess things up.
20 namespace is_incrementable_
21 {
22   // a type returned from operator++ when no increment is found in the
23   // type's own namespace
24   struct tag {};
25   
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&); };
30
31   // This is a last-resort operator++ for when none other is found
32   tag operator++(any const&);
33   tag operator++(any const&,int);
34
35 # if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3202)) \
36     || BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
37 #  define BOOST_comma(a,b) (a)
38 # else 
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)
42 # endif 
43   
44   // two check overloads help us identify which operator++ was picked
45   char (& check(tag) )[2];
46   
47   template <class T>
48   char check(T const&);
49   
50
51   template <class T>
52   struct impl
53   {
54       static typename remove_cv<T>::type& x;
55
56       BOOST_STATIC_CONSTANT(
57           bool
58         , value = sizeof(is_incrementable_::check(BOOST_comma(++x,0))) == 1
59       );
60   };
61
62   template <class T>
63   struct postfix_impl
64   {
65       static typename remove_cv<T>::type& x;
66
67       BOOST_STATIC_CONSTANT(
68           bool
69         , value = sizeof(is_incrementable_::check(BOOST_comma(x++,0))) == 1
70       );
71   };
72 }
73
74 # undef BOOST_comma
75
76 template <class T>
77 struct is_incrementable
78   : mpl::bool_< ::boost::detail::is_incrementable_::impl<T>::value>
79 {
80 };
81
82 template <class T>
83 struct is_postfix_incrementable
84   : mpl::bool_< ::boost::detail::is_incrementable_::postfix_impl<T>::value>
85 {
86 };
87
88 }} // namespace boost::detail
89
90 #endif // IS_INCREMENTABLE_DWA200415_HPP