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