Chris@16: // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com) Chris@16: // (C) Copyright 2005-2007 Jonathan Turkanis Chris@16: // (C) Copyright David Abrahams 2004. Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) Chris@16: Chris@16: // See http://www.boost.org/libs/iostreams for documentation. Chris@16: Chris@16: #ifndef BOOST_IOSTREAMS_DETAIL_IS_DEREFERENCEABLE_HPP_INCLUDED Chris@16: #define BOOST_IOSTREAMS_DETAIL_IS_DEREFERENCEABLE_HPP_INCLUDED Chris@16: Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: Chris@16: namespace boost { namespace iostreams { namespace detail { Chris@16: Chris@16: // is_dereferenceable metafunction Chris@16: // Chris@16: // Requires: Given x of type T&, if the expression *x is well-formed Chris@16: // it must have complete type; otherwise, it must neither be ambiguous Chris@16: // nor violate access. Chris@16: Chris@16: // This namespace ensures that ADL doesn't mess things up. Chris@16: namespace is_dereferenceable_ Chris@16: { Chris@16: // a type returned from operator* when no increment is found in the Chris@16: // type's own namespace Chris@16: struct tag {}; Chris@16: Chris@16: // any soaks up implicit conversions and makes the following Chris@16: // operator* less-preferred than any other such operator that Chris@16: // might be found via ADL. Chris@16: struct any { template any(T const&); }; Chris@16: Chris@16: // This is a last-resort operator* for when none other is found Chris@16: tag operator*(any const&); Chris@16: Chris@16: # if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3202)) \ Chris@16: || BOOST_WORKAROUND(BOOST_MSVC, <= 1300) Chris@16: # define BOOST_comma(a,b) (a) Chris@16: # else Chris@16: // In case an operator++ is found that returns void, we'll use ++x,0 Chris@16: tag operator,(tag,int); Chris@16: # define BOOST_comma(a,b) (a,b) Chris@16: # endif Chris@16: Chris@16: // two check overloads help us identify which operator++ was picked Chris@16: char (& check_increment(tag) )[2]; Chris@16: Chris@16: template Chris@16: char check_increment(T const&); Chris@16: Chris@16: template Chris@16: struct impl Chris@16: { Chris@16: static typename boost::remove_cv::type& x; Chris@16: Chris@16: BOOST_STATIC_CONSTANT( Chris@16: bool Chris@16: , value = sizeof(is_dereferenceable_::check_increment(BOOST_comma(*x,0))) == 1 Chris@16: ); Chris@16: }; Chris@16: } Chris@16: Chris@16: # undef BOOST_comma Chris@16: Chris@16: template Chris@16: struct is_dereferenceable Chris@16: BOOST_TT_AUX_BOOL_C_BASE(is_dereferenceable_::impl::value) Chris@16: { Chris@16: BOOST_TT_AUX_BOOL_TRAIT_VALUE_DECL(is_dereferenceable_::impl::value) Chris@16: BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_dereferenceable,(T)) Chris@16: }; Chris@16: Chris@16: } } Chris@16: Chris@16: BOOST_TT_AUX_TEMPLATE_ARITY_SPEC(1, ::boost::iostreams::detail::is_dereferenceable) Chris@16: Chris@16: } // End namespaces detail, iostreams, boost. Chris@16: Chris@16: #endif // BOOST_IOSTREAMS_DETAIL_IS_DEREFERENCEABLE_HPP_INCLUDED