File indexing completed on 2025-01-18 09:38:50
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_IOSTREAMS_DETAIL_WRAP_UNWRAP_HPP_INCLUDED
0009 #define BOOST_IOSTREAMS_DETAIL_WRAP_UNWRAP_HPP_INCLUDED
0010
0011 #if defined(_MSC_VER)
0012 # pragma once
0013 #endif
0014
0015 #include <boost/config.hpp> // SFINAE, MSVC.
0016 #include <boost/detail/workaround.hpp>
0017 #include <boost/iostreams/detail/enable_if_stream.hpp>
0018 #include <boost/iostreams/traits_fwd.hpp> // is_std_io.
0019 #include <boost/mpl/bool.hpp>
0020 #include <boost/mpl/identity.hpp>
0021 #include <boost/mpl/eval_if.hpp>
0022 #include <boost/mpl/if.hpp>
0023 #include <boost/ref.hpp>
0024
0025 namespace boost { namespace iostreams { namespace detail {
0026
0027
0028
0029 template<typename T>
0030 struct wrapped_type
0031 : mpl::if_<is_std_io<T>, reference_wrapper<T>, T>
0032 { };
0033
0034 template<typename T>
0035 struct unwrapped_type
0036 : unwrap_reference<T>
0037 { };
0038
0039 template<typename T>
0040 struct unwrap_ios
0041 : mpl::eval_if<
0042 is_std_io<T>,
0043 unwrap_reference<T>,
0044 mpl::identity<T>
0045 >
0046 { };
0047
0048
0049
0050 #ifndef BOOST_NO_SFINAE
0051 template<typename T>
0052 inline T wrap(const T& t BOOST_IOSTREAMS_DISABLE_IF_STREAM(T))
0053 { return t; }
0054
0055 template<typename T>
0056 inline typename wrapped_type<T>::type
0057 wrap(T& t BOOST_IOSTREAMS_ENABLE_IF_STREAM(T)) { return boost::ref(t); }
0058 #else
0059 template<typename T>
0060 inline typename wrapped_type<T>::type
0061 wrap_impl(const T& t, mpl::true_) { return boost::ref(const_cast<T&>(t)); }
0062
0063 template<typename T>
0064 inline typename wrapped_type<T>::type
0065 wrap_impl(T& t, mpl::true_) { return boost::ref(t); }
0066
0067 template<typename T>
0068 inline typename wrapped_type<T>::type
0069 wrap_impl(const T& t, mpl::false_) { return t; }
0070
0071 template<typename T>
0072 inline typename wrapped_type<T>::type
0073 wrap_impl(T& t, mpl::false_) { return t; }
0074
0075 template<typename T>
0076 inline typename wrapped_type<T>::type
0077 wrap(const T& t) { return wrap_impl(t, is_std_io<T>()); }
0078
0079 template<typename T>
0080 inline typename wrapped_type<T>::type
0081 wrap(T& t) { return wrap_impl(t, is_std_io<T>()); }
0082 #endif
0083
0084
0085
0086 template<typename T>
0087 typename unwrapped_type<T>::type&
0088 unwrap(const reference_wrapper<T>& ref) { return ref.get(); }
0089
0090 template<typename T>
0091 typename unwrapped_type<T>::type& unwrap(T& t) { return t; }
0092
0093 template<typename T>
0094 const typename unwrapped_type<T>::type& unwrap(const T& t) { return t; }
0095
0096 } } }
0097
0098 #endif