]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/iostreams/include/boost/iostreams/detail/wrap_unwrap.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / iostreams / include / boost / iostreams / detail / wrap_unwrap.hpp
CommitLineData
7c673cae
FG
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.)
5
6// See http://www.boost.org/libs/iostreams for documentation.
7
8#ifndef BOOST_IOSTREAMS_DETAIL_WRAP_UNWRAP_HPP_INCLUDED
9#define BOOST_IOSTREAMS_DETAIL_WRAP_UNWRAP_HPP_INCLUDED
10
11#if defined(_MSC_VER)
12# pragma once
13#endif
14
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>
24
25namespace boost { namespace iostreams { namespace detail {
26
27//------------------Definition of wrap/unwrap traits--------------------------//
28
29template<typename T>
30struct wrapped_type
31 : mpl::if_<is_std_io<T>, reference_wrapper<T>, T>
32 { };
33
34template<typename T>
35struct unwrapped_type
36 : unwrap_reference<T>
37 { };
38
39template<typename T>
40struct unwrap_ios
41 : mpl::eval_if<
42 is_std_io<T>,
43 unwrap_reference<T>,
44 mpl::identity<T>
45 >
46 { };
47
48//------------------Definition of wrap----------------------------------------//
49
50#ifndef BOOST_NO_SFINAE //----------------------------------------------------//
51 template<typename T>
52 inline T wrap(const T& t BOOST_IOSTREAMS_DISABLE_IF_STREAM(T))
53 { return t; }
54
55 template<typename 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 //-------------------------------------------//
59 template<typename T>
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)); }
62
63 template<typename 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); }
66
67 template<typename T>
68 inline typename wrapped_type<T>::type
69 wrap_impl(const T& t, mpl::false_) { return t; }
70
71 template<typename T>
72 inline typename wrapped_type<T>::type
73 wrap_impl(T& t, mpl::false_) { return t; }
74
75 template<typename T>
76 inline typename wrapped_type<T>::type
77 wrap(const T& t) { return wrap_impl(t, is_std_io<T>()); }
78
79 template<typename 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 //------------------------------------------//
83
84//------------------Definition of unwrap--------------------------------------//
85
86template<typename T>
87typename unwrapped_type<T>::type&
88unwrap(const reference_wrapper<T>& ref) { return ref.get(); }
89
90template<typename T>
91typename unwrapped_type<T>::type& unwrap(T& t) { return t; }
92
93template<typename T>
94const typename unwrapped_type<T>::type& unwrap(const T& t) { return t; }
95
96} } } // End namespaces detail, iostreams, boost.
97
98#endif // #ifndef BOOST_IOSTREAMS_DETAIL_WRAP_UNWRAP_HPP_INCLUDED