[857] | 1 | // (C) Copyright David Abrahams 2004.
|
---|
| 2 | // (C) Copyright Jonathan Turkanis 2005.
|
---|
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
---|
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
|
---|
| 5 |
|
---|
| 6 | // See http://www.boost.org/libs/iostreams for documentation.
|
---|
| 7 |
|
---|
| 8 | #ifndef BOOST_IOSTREAMS_DETAIL_IS_DEREFERENCEABLE_HPP_INCLUDED
|
---|
| 9 | #define BOOST_IOSTREAMS_DETAIL_IS_DEREFERENCEABLE_HPP_INCLUDED
|
---|
| 10 |
|
---|
| 11 | # include <boost/type_traits/detail/bool_trait_def.hpp>
|
---|
| 12 | # include <boost/type_traits/detail/template_arity_spec.hpp>
|
---|
| 13 | # include <boost/type_traits/remove_cv.hpp>
|
---|
| 14 | # include <boost/mpl/aux_/lambda_support.hpp>
|
---|
| 15 | # include <boost/mpl/bool.hpp>
|
---|
| 16 | # include <boost/detail/workaround.hpp>
|
---|
| 17 |
|
---|
| 18 | namespace boost { namespace iostreams { namespace detail {
|
---|
| 19 |
|
---|
| 20 | // is_dereferenceable<T> metafunction
|
---|
| 21 | //
|
---|
| 22 | // Requires: Given x of type T&, if the expression *x is well-formed
|
---|
| 23 | // it must have complete type; otherwise, it must neither be ambiguous
|
---|
| 24 | // nor violate access.
|
---|
| 25 |
|
---|
| 26 | // This namespace ensures that ADL doesn't mess things up.
|
---|
| 27 | namespace is_dereferenceable_
|
---|
| 28 | {
|
---|
| 29 | // a type returned from operator* when no increment is found in the
|
---|
| 30 | // type's own namespace
|
---|
| 31 | struct tag {};
|
---|
| 32 |
|
---|
| 33 | // any soaks up implicit conversions and makes the following
|
---|
| 34 | // operator* less-preferred than any other such operator that
|
---|
| 35 | // might be found via ADL.
|
---|
| 36 | struct any { template <class T> any(T const&); };
|
---|
| 37 |
|
---|
| 38 | // This is a last-resort operator* for when none other is found
|
---|
| 39 | tag operator*(any const&);
|
---|
| 40 |
|
---|
| 41 | # if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3202)) \
|
---|
| 42 | || BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
|
---|
| 43 | # define BOOST_comma(a,b) (a)
|
---|
| 44 | # else
|
---|
| 45 | // In case an operator++ is found that returns void, we'll use ++x,0
|
---|
| 46 | tag operator,(tag,int);
|
---|
| 47 | # define BOOST_comma(a,b) (a,b)
|
---|
| 48 | # endif
|
---|
| 49 |
|
---|
| 50 | // two check overloads help us identify which operator++ was picked
|
---|
| 51 | char (& check(tag) )[2];
|
---|
| 52 |
|
---|
| 53 | template <class T>
|
---|
| 54 | char check(T const&);
|
---|
| 55 |
|
---|
| 56 | template <class T>
|
---|
| 57 | struct impl
|
---|
| 58 | {
|
---|
| 59 | static typename boost::remove_cv<T>::type& x;
|
---|
| 60 |
|
---|
| 61 | BOOST_STATIC_CONSTANT(
|
---|
| 62 | bool
|
---|
| 63 | , value = sizeof(is_dereferenceable_::check(BOOST_comma(*x,0))) == 1
|
---|
| 64 | );
|
---|
| 65 | };
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | # undef BOOST_comma
|
---|
| 69 |
|
---|
| 70 | template<typename T>
|
---|
| 71 | struct is_dereferenceable
|
---|
| 72 | BOOST_TT_AUX_BOOL_C_BASE(is_dereferenceable_::impl<T>::value)
|
---|
| 73 | {
|
---|
| 74 | BOOST_TT_AUX_BOOL_TRAIT_VALUE_DECL(is_dereferenceable_::impl<T>::value)
|
---|
| 75 | BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_dereferenceable,(T))
|
---|
| 76 | };
|
---|
| 77 |
|
---|
| 78 | } }
|
---|
| 79 |
|
---|
| 80 | BOOST_TT_AUX_TEMPLATE_ARITY_SPEC(1, ::boost::iostreams::detail::is_dereferenceable)
|
---|
| 81 |
|
---|
| 82 | } // End namespaces detail, iostreams, boost.
|
---|
| 83 |
|
---|
| 84 | #endif // BOOST_IOSTREAMS_DETAIL_IS_DEREFERENCEABLE_HPP_INCLUDED
|
---|