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