Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / iterator / is_lvalue_iterator.hpp
1 // Copyright David Abrahams 2003. 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_LVALUE_ITERATOR_DWA2003112_HPP
5 # define IS_LVALUE_ITERATOR_DWA2003112_HPP
6
7 #include <boost/iterator.hpp>
8
9 #include <boost/detail/workaround.hpp>
10 #include <boost/detail/iterator.hpp>
11
12 #include <boost/iterator/detail/any_conversion_eater.hpp>
13
14 // should be the last #includes
15 #include <boost/type_traits/detail/bool_trait_def.hpp>
16 #include <boost/iterator/detail/config_def.hpp>
17
18 #ifndef BOOST_NO_IS_CONVERTIBLE
19
20 namespace boost {
21
22 namespace iterators {
23
24 namespace detail
25 {
26 #ifndef BOOST_NO_LVALUE_RETURN_DETECTION
27   // Calling lvalue_preserver( <expression>, 0 ) returns a reference
28   // to the expression's result if <expression> is an lvalue, or
29   // not_an_lvalue() otherwise.
30   struct not_an_lvalue {};
31
32   template <class T>
33   T& lvalue_preserver(T&, int);
34
35   template <class U>
36   not_an_lvalue lvalue_preserver(U const&, ...);
37
38 # define BOOST_LVALUE_PRESERVER(expr) detail::lvalue_preserver(expr,0)
39
40 #else
41
42 # define BOOST_LVALUE_PRESERVER(expr) expr
43
44 #endif
45
46   // Guts of is_lvalue_iterator.  Value is the iterator's value_type
47   // and the result is computed in the nested rebind template.
48   template <class Value>
49   struct is_lvalue_iterator_impl
50   {
51       // Eat implicit conversions so we don't report true for things
52       // convertible to Value const&
53       struct conversion_eater
54       {
55           conversion_eater(Value&);
56       };
57
58       static char tester(conversion_eater, int);
59       static char (& tester(any_conversion_eater, ...) )[2];
60
61       template <class It>
62       struct rebind
63       {
64           static It& x;
65
66           BOOST_STATIC_CONSTANT(
67               bool
68             , value = (
69                 sizeof(
70                     is_lvalue_iterator_impl<Value>::tester(
71                         BOOST_LVALUE_PRESERVER(*x), 0
72                     )
73                 ) == 1
74             )
75           );
76       };
77   };
78
79 #undef BOOST_LVALUE_PRESERVER
80
81   //
82   // void specializations to handle std input and output iterators
83   //
84   template <>
85   struct is_lvalue_iterator_impl<void>
86   {
87       template <class It>
88       struct rebind : boost::mpl::false_
89       {};
90   };
91
92 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
93   template <>
94   struct is_lvalue_iterator_impl<const void>
95   {
96       template <class It>
97       struct rebind : boost::mpl::false_
98       {};
99   };
100
101   template <>
102   struct is_lvalue_iterator_impl<volatile void>
103   {
104       template <class It>
105       struct rebind : boost::mpl::false_
106       {};
107   };
108
109   template <>
110   struct is_lvalue_iterator_impl<const volatile void>
111   {
112       template <class It>
113       struct rebind : boost::mpl::false_
114       {};
115   };
116 #endif
117
118   //
119   // This level of dispatching is required for Borland.  We might save
120   // an instantiation by removing it for others.
121   //
122   template <class It>
123   struct is_readable_lvalue_iterator_impl
124     : is_lvalue_iterator_impl<
125           BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<It>::value_type const
126       >::template rebind<It>
127   {};
128
129   template <class It>
130   struct is_non_const_lvalue_iterator_impl
131     : is_lvalue_iterator_impl<
132           BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<It>::value_type
133       >::template rebind<It>
134   {};
135 } // namespace detail
136
137 // Define the trait with full mpl lambda capability and various broken
138 // compiler workarounds
139 BOOST_TT_AUX_BOOL_TRAIT_DEF1(
140     is_lvalue_iterator,T,::boost::iterators::detail::is_readable_lvalue_iterator_impl<T>::value)
141
142 BOOST_TT_AUX_BOOL_TRAIT_DEF1(
143     is_non_const_lvalue_iterator,T,::boost::iterators::detail::is_non_const_lvalue_iterator_impl<T>::value)
144
145 } // namespace iterators
146
147 using iterators::is_lvalue_iterator;
148 using iterators::is_non_const_lvalue_iterator;
149
150 } // namespace boost
151
152 #endif
153
154 #include <boost/iterator/detail/config_undef.hpp>
155 #include <boost/type_traits/detail/bool_trait_undef.hpp>
156
157 #endif // IS_LVALUE_ITERATOR_DWA2003112_HPP