Chris@16: // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com) Chris@16: // (C) Copyright 2003-2007 Jonathan Turkanis 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_WRAP_UNWRAP_HPP_INCLUDED Chris@16: #define BOOST_IOSTREAMS_DETAIL_WRAP_UNWRAP_HPP_INCLUDED Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1020) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: #include // SFINAE, MSVC. Chris@16: #include Chris@16: #include Chris@16: #include // is_std_io. 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: //------------------Definition of wrap/unwrap traits--------------------------// Chris@16: Chris@16: template Chris@16: struct wrapped_type Chris@16: : mpl::if_, reference_wrapper, T> Chris@16: { }; Chris@16: Chris@16: template Chris@16: struct unwrapped_type Chris@16: : unwrap_reference Chris@16: { }; Chris@16: Chris@16: template Chris@16: struct unwrap_ios Chris@16: : mpl::eval_if< Chris@16: is_std_io, Chris@16: unwrap_reference, Chris@16: mpl::identity Chris@16: > Chris@16: { }; Chris@16: Chris@16: //------------------Definition of wrap----------------------------------------// Chris@16: Chris@16: #ifndef BOOST_NO_SFINAE //----------------------------------------------------// Chris@16: template Chris@16: inline T wrap(const T& t BOOST_IOSTREAMS_DISABLE_IF_STREAM(T)) Chris@16: { return t; } Chris@16: Chris@16: template Chris@16: inline typename wrapped_type::type Chris@16: wrap(T& t BOOST_IOSTREAMS_ENABLE_IF_STREAM(T)) { return boost::ref(t); } Chris@16: #else // #ifndef BOOST_NO_SFINAE //-------------------------------------------// Chris@16: template Chris@16: inline typename wrapped_type::type // BCC 5.x needs namespace qualification. Chris@16: wrap_impl(const T& t, mpl::true_) { return boost::ref(const_cast(t)); } Chris@16: Chris@16: template Chris@16: inline typename wrapped_type::type // BCC 5.x needs namespace qualification. Chris@16: wrap_impl(T& t, mpl::true_) { return boost::ref(t); } Chris@16: Chris@16: template Chris@16: inline typename wrapped_type::type Chris@16: wrap_impl(const T& t, mpl::false_) { return t; } Chris@16: Chris@16: template Chris@16: inline typename wrapped_type::type Chris@16: wrap_impl(T& t, mpl::false_) { return t; } Chris@16: Chris@16: template Chris@16: inline typename wrapped_type::type Chris@16: wrap(const T& t) { return wrap_impl(t, is_std_io()); } Chris@16: Chris@16: template Chris@16: inline typename wrapped_type::type Chris@16: wrap(T& t) { return wrap_impl(t, is_std_io()); } Chris@16: #endif // #ifndef BOOST_NO_SFINAE //------------------------------------------// Chris@16: Chris@16: //------------------Definition of unwrap--------------------------------------// Chris@16: Chris@16: #if !BOOST_WORKAROUND(BOOST_MSVC, < 1310) //----------------------------------// Chris@16: Chris@16: template Chris@16: typename unwrapped_type::type& Chris@16: unwrap(const reference_wrapper& ref) { return ref.get(); } Chris@16: Chris@16: template Chris@16: typename unwrapped_type::type& unwrap(T& t) { return t; } Chris@16: Chris@16: template Chris@16: const typename unwrapped_type::type& unwrap(const T& t) { return t; } Chris@16: Chris@16: #else // #if !BOOST_WORKAROUND(BOOST_MSVC, < 1310) //-------------------------// Chris@16: Chris@16: // Since unwrap is a potential bottleneck, we avoid runtime tag dispatch. Chris@16: template Chris@16: struct unwrap_impl; Chris@16: Chris@16: template<> Chris@16: struct unwrap_impl { Chris@16: template Chris@16: static typename unwrapped_type::type& unwrap(const T& t) Chris@16: { return t.get(); } Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct unwrap_impl { Chris@16: template Chris@16: static typename unwrapped_type::type& unwrap(const T& t) Chris@16: { return const_cast(t); } Chris@16: }; Chris@16: Chris@16: template Chris@16: typename unwrapped_type::type& Chris@16: unwrap(const T& t) Chris@16: { return unwrap_impl::value>::unwrap(t); } Chris@16: Chris@16: #endif // #if !BOOST_WORKAROUND(BOOST_MSVC, < 1310) //------------------------// Chris@16: Chris@16: } } } // End namespaces detail, iostreams, boost. Chris@16: Chris@16: #endif // #ifndef BOOST_IOSTREAMS_DETAIL_WRAP_UNWRAP_HPP_INCLUDED