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
7 #include <boost/detail/workaround.hpp>
9 #include <boost/type_traits/add_lvalue_reference.hpp>
10 #include <boost/iterator/detail/any_conversion_eater.hpp>
11 #include <boost/mpl/bool.hpp>
12 #include <boost/mpl/aux_/lambda_support.hpp>
16 // should be the last #includes
17 #include <boost/type_traits/integral_constant.hpp>
18 #include <boost/iterator/detail/config_def.hpp>
20 #ifndef BOOST_NO_IS_CONVERTIBLE
28 #ifndef BOOST_NO_LVALUE_RETURN_DETECTION
29 // Calling lvalue_preserver( <expression>, 0 ) returns a reference
30 // to the expression's result if <expression> is an lvalue, or
31 // not_an_lvalue() otherwise.
32 struct not_an_lvalue {};
35 T& lvalue_preserver(T&, int);
38 not_an_lvalue lvalue_preserver(U const&, ...);
40 # define BOOST_LVALUE_PRESERVER(expr) detail::lvalue_preserver(expr,0)
44 # define BOOST_LVALUE_PRESERVER(expr) expr
48 // Guts of is_lvalue_iterator. Value is the iterator's value_type
49 // and the result is computed in the nested rebind template.
50 template <class Value>
51 struct is_lvalue_iterator_impl
53 // Eat implicit conversions so we don't report true for things
54 // convertible to Value const&
55 struct conversion_eater
57 conversion_eater(typename add_lvalue_reference<Value>::type);
60 static char tester(conversion_eater, int);
61 static char (& tester(any_conversion_eater, ...) )[2];
68 BOOST_STATIC_CONSTANT(
72 is_lvalue_iterator_impl<Value>::tester(
73 BOOST_LVALUE_PRESERVER(*x), 0
81 #undef BOOST_LVALUE_PRESERVER
84 // void specializations to handle std input and output iterators
87 struct is_lvalue_iterator_impl<void>
90 struct rebind : boost::mpl::false_
94 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
96 struct is_lvalue_iterator_impl<const void>
99 struct rebind : boost::mpl::false_
104 struct is_lvalue_iterator_impl<volatile void>
107 struct rebind : boost::mpl::false_
112 struct is_lvalue_iterator_impl<const volatile void>
115 struct rebind : boost::mpl::false_
121 // This level of dispatching is required for Borland. We might save
122 // an instantiation by removing it for others.
125 struct is_readable_lvalue_iterator_impl
126 : is_lvalue_iterator_impl<
127 BOOST_DEDUCED_TYPENAME std::iterator_traits<It>::value_type const
128 >::template rebind<It>
132 struct is_non_const_lvalue_iterator_impl
133 : is_lvalue_iterator_impl<
134 BOOST_DEDUCED_TYPENAME std::iterator_traits<It>::value_type
135 >::template rebind<It>
137 } // namespace detail
139 template< typename T > struct is_lvalue_iterator
140 : public ::boost::integral_constant<bool,::boost::iterators::detail::is_readable_lvalue_iterator_impl<T>::value>
143 BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_lvalue_iterator,(T))
146 template< typename T > struct is_non_const_lvalue_iterator
147 : public ::boost::integral_constant<bool,::boost::iterators::detail::is_non_const_lvalue_iterator_impl<T>::value>
150 BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_non_const_lvalue_iterator,(T))
153 } // namespace iterators
155 using iterators::is_lvalue_iterator;
156 using iterators::is_non_const_lvalue_iterator;
162 #include <boost/iterator/detail/config_undef.hpp>
164 #endif // IS_LVALUE_ITERATOR_DWA2003112_HPP