1 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
2 // (C) Copyright 2003-2007 Jonathan Turkanis
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.)
6 // See http://www.boost.org/libs/iostreams for documentation.
8 #ifndef BOOST_IOSTREAMS_DETAIL_WRAP_UNWRAP_HPP_INCLUDED
9 #define BOOST_IOSTREAMS_DETAIL_WRAP_UNWRAP_HPP_INCLUDED
15 #include <boost/config.hpp> // SFINAE, MSVC.
16 #include <boost/detail/workaround.hpp>
17 #include <boost/iostreams/detail/enable_if_stream.hpp>
18 #include <boost/iostreams/traits_fwd.hpp> // is_std_io.
19 #include <boost/mpl/bool.hpp>
20 #include <boost/mpl/identity.hpp>
21 #include <boost/mpl/eval_if.hpp>
22 #include <boost/mpl/if.hpp>
23 #include <boost/ref.hpp>
25 namespace boost { namespace iostreams { namespace detail {
27 //------------------Definition of wrap/unwrap traits--------------------------//
31 : mpl::if_<is_std_io<T>, reference_wrapper<T>, T>
48 //------------------Definition of wrap----------------------------------------//
50 #ifndef BOOST_NO_SFINAE //----------------------------------------------------//
52 inline T wrap(const T& t BOOST_IOSTREAMS_DISABLE_IF_STREAM(T))
56 inline typename wrapped_type<T>::type
57 wrap(T& t BOOST_IOSTREAMS_ENABLE_IF_STREAM(T)) { return boost::ref(t); }
58 #else // #ifndef BOOST_NO_SFINAE //-------------------------------------------//
60 inline typename wrapped_type<T>::type // BCC 5.x needs namespace qualification.
61 wrap_impl(const T& t, mpl::true_) { return boost::ref(const_cast<T&>(t)); }
64 inline typename wrapped_type<T>::type // BCC 5.x needs namespace qualification.
65 wrap_impl(T& t, mpl::true_) { return boost::ref(t); }
68 inline typename wrapped_type<T>::type
69 wrap_impl(const T& t, mpl::false_) { return t; }
72 inline typename wrapped_type<T>::type
73 wrap_impl(T& t, mpl::false_) { return t; }
76 inline typename wrapped_type<T>::type
77 wrap(const T& t) { return wrap_impl(t, is_std_io<T>()); }
80 inline typename wrapped_type<T>::type
81 wrap(T& t) { return wrap_impl(t, is_std_io<T>()); }
82 #endif // #ifndef BOOST_NO_SFINAE //------------------------------------------//
84 //------------------Definition of unwrap--------------------------------------//
87 typename unwrapped_type<T>::type&
88 unwrap(const reference_wrapper<T>& ref) { return ref.get(); }
91 typename unwrapped_type<T>::type& unwrap(T& t) { return t; }
94 const typename unwrapped_type<T>::type& unwrap(const T& t) { return t; }
96 } } } // End namespaces detail, iostreams, boost.
98 #endif // #ifndef BOOST_IOSTREAMS_DETAIL_WRAP_UNWRAP_HPP_INCLUDED