Update contrib.
1 // (C) Copyright Jonathan Turkanis 2003.
2 // Distributed under the Boost Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
5 // See http://www.boost.org/libs/iostreams for documentation.
7 #ifndef BOOST_IOSTREAMS_DETAIL_RESOLVE_HPP_INCLUDED
8 #define BOOST_IOSTREAMS_DETAIL_RESOLVE_HPP_INCLUDED
10 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
14 #include <boost/config.hpp> // partial spec, put size_t in std.
15 #include <cstddef> // std::size_t.
16 #include <boost/detail/is_incrementable.hpp>
17 #include <boost/detail/workaround.hpp>
18 #include <boost/iostreams/detail/adapter/mode_adapter.hpp>
19 #include <boost/iostreams/detail/adapter/output_iterator_adapter.hpp>
20 #include <boost/iostreams/detail/adapter/range_adapter.hpp>
21 #include <boost/iostreams/detail/config/gcc.hpp>
22 #include <boost/iostreams/detail/config/overload_resolution.hpp>
23 #include <boost/iostreams/detail/config/wide_streams.hpp>
24 #include <boost/iostreams/detail/enable_if_stream.hpp>
25 #include <boost/iostreams/detail/is_dereferenceable.hpp>
26 #include <boost/iostreams/detail/is_iterator_range.hpp>
27 #include <boost/iostreams/detail/select.hpp>
28 #include <boost/iostreams/detail/wrap_unwrap.hpp>
29 #include <boost/iostreams/device/array.hpp>
30 #include <boost/iostreams/traits.hpp>
31 #include <boost/mpl/and.hpp>
32 #include <boost/mpl/bool.hpp> // true_.
33 #include <boost/mpl/if.hpp>
34 #include <boost/range/iterator_range.hpp>
35 #include <boost/type_traits/is_array.hpp>
38 #include <boost/iostreams/detail/config/disable_warnings.hpp> // VC7.1 C4224.
40 namespace boost { namespace iostreams { namespace detail {
42 //------------------Definition of resolve-------------------------------------//
44 #ifndef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION //-------------------------//
46 template<typename Mode, typename Ch, typename T>
47 struct resolve_traits {
51 boost::detail::is_incrementable<T>, // Must come first
52 is_dereferenceable<T> // for CW 9.[0-4]
54 output_iterator_adapter<Mode, Ch, T>,
59 # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //-------------------------------//
61 template<typename Mode, typename Ch, typename T>
62 typename resolve_traits<Mode, Ch, T>::type
64 BOOST_IOSTREAMS_DISABLE_IF_STREAM(T)
66 // I suspect that the compilers which require this workaround may
67 // be correct, but I'm not sure why :(
68 #if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, BOOST_TESTED_AT(810)) ||\
69 BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205)) || \
70 BOOST_WORKAROUND(BOOST_IOSTREAMS_GCC, BOOST_TESTED_AT(400)) \
72 , typename disable_if< is_iterator_range<T> >::type* = 0
76 typedef typename resolve_traits<Mode, Ch, T>::type return_type;
77 return return_type(t);
80 template<typename Mode, typename Ch, typename Tr>
81 mode_adapter< Mode, std::basic_streambuf<Ch, Tr> >
82 resolve(std::basic_streambuf<Ch, Tr>& sb)
83 { return mode_adapter< Mode, std::basic_streambuf<Ch, Tr> >(wrap(sb)); }
85 template<typename Mode, typename Ch, typename Tr>
86 mode_adapter< Mode, std::basic_istream<Ch, Tr> >
87 resolve(std::basic_istream<Ch, Tr>& is)
88 { return mode_adapter< Mode, std::basic_istream<Ch, Tr> >(wrap(is)); }
90 template<typename Mode, typename Ch, typename Tr>
91 mode_adapter< Mode, std::basic_ostream<Ch, Tr> >
92 resolve(std::basic_ostream<Ch, Tr>& os)
93 { return mode_adapter< Mode, std::basic_ostream<Ch, Tr> >(wrap(os)); }
95 template<typename Mode, typename Ch, typename Tr>
96 mode_adapter< Mode, std::basic_iostream<Ch, Tr> >
97 resolve(std::basic_iostream<Ch, Tr>& io)
98 { return mode_adapter< Mode, std::basic_iostream<Ch, Tr> >(wrap(io)); }
100 template<typename Mode, typename Ch, std::size_t N>
101 array_adapter<Mode, Ch> resolve(Ch (&array)[N])
102 { return array_adapter<Mode, Ch>(array); }
104 template<typename Mode, typename Ch, typename Iter>
105 range_adapter< Mode, boost::iterator_range<Iter> >
106 resolve(const boost::iterator_range<Iter>& rng)
107 { return range_adapter< Mode, boost::iterator_range<Iter> >(rng); }
109 # else // # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //---------------------//
111 template<typename Mode, typename Ch, typename T>
112 typename resolve_traits<Mode, Ch, T>::type
114 BOOST_IOSTREAMS_DISABLE_IF_STREAM(T)
115 #if defined(__GNUC__)
116 , typename disable_if< is_iterator_range<T> >::type* = 0
120 typedef typename resolve_traits<Mode, Ch, T>::type return_type;
121 return return_type(t);
124 template<typename Mode, typename Ch>
125 mode_adapter<Mode, std::streambuf>
126 resolve(std::streambuf& sb)
127 { return mode_adapter<Mode, std::streambuf>(wrap(sb)); }
129 template<typename Mode, typename Ch>
130 mode_adapter<Mode, std::istream>
131 resolve(std::istream& is)
132 { return mode_adapter<Mode, std::istream>(wrap(is)); }
134 template<typename Mode, typename Ch>
135 mode_adapter<Mode, std::ostream>
136 resolve(std::ostream& os)
137 { return mode_adapter<Mode, std::ostream>(wrap(os)); }
139 template<typename Mode, typename Ch>
140 mode_adapter<Mode, std::iostream>
141 resolve(std::iostream& io)
142 { return mode_adapter<Mode, std::iostream>(wrap(io)); }
144 template<typename Mode, typename Ch, std::size_t N>
145 array_adapter<Mode, Ch> resolve(Ch (&array)[N])
146 { return array_adapter<Mode, Ch>(array); }
148 template<typename Mode, typename Ch, typename Iter>
149 range_adapter< Mode, boost::iterator_range<Iter> >
150 resolve(const boost::iterator_range<Iter>& rng)
151 { return range_adapter< Mode, boost::iterator_range<Iter> >(rng); }
153 # endif // # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //--------------------//
154 #else // #ifndef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION //----------------//
156 template<typename Mode, typename Ch, typename T>
157 struct resolve_traits {
158 // Note: test for is_iterator_range must come before test for output
161 iostreams::select< // Disambiguation for Tru64.
163 mode_adapter<Mode, T>,
164 is_iterator_range<T>,
165 range_adapter<Mode, T>,
167 is_dereferenceable<T>,
168 boost::detail::is_incrementable<T>
170 output_iterator_adapter<Mode, Ch, T>,
172 array_adapter<Mode, T>,
174 #if !BOOST_WORKAROUND(__BORLANDC__, < 0x600)
182 template<typename Mode, typename Ch, typename T>
183 typename resolve_traits<Mode, Ch, T>::type
184 resolve(const T& t, mpl::true_)
185 { // Bad overload resolution.
186 typedef typename resolve_traits<Mode, Ch, T>::type return_type;
187 return return_type(wrap(const_cast<T&>(t)));
190 template<typename Mode, typename Ch, typename T>
191 typename resolve_traits<Mode, Ch, T>::type
192 resolve(const T& t, mpl::false_)
194 typedef typename resolve_traits<Mode, Ch, T>::type return_type;
195 return return_type(t);
198 template<typename Mode, typename Ch, typename T>
199 typename resolve_traits<Mode, Ch, T>::type
200 resolve(const T& t BOOST_IOSTREAMS_DISABLE_IF_STREAM(T))
201 { return resolve<Mode, Ch>(t, is_std_io<T>()); }
203 # if !BOOST_WORKAROUND(__BORLANDC__, < 0x600) && \
204 !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) && \
205 !defined(__GNUC__) // ---------------------------------------------------//
207 template<typename Mode, typename Ch, typename T>
208 typename resolve_traits<Mode, Ch, T>::type
209 resolve(T& t, mpl::true_)
211 typedef typename resolve_traits<Mode, Ch, T>::type return_type;
212 return return_type(wrap(t));
215 template<typename Mode, typename Ch, typename T>
216 typename resolve_traits<Mode, Ch, T>::type
217 resolve(T& t, mpl::false_)
219 typedef typename resolve_traits<Mode, Ch, T>::type return_type;
220 return return_type(t);
223 template<typename Mode, typename Ch, typename T>
224 typename resolve_traits<Mode, Ch, T>::type
225 resolve(T& t BOOST_IOSTREAMS_ENABLE_IF_STREAM(T))
226 { return resolve<Mode, Ch>(t, is_std_io<T>()); }
228 # endif // Borland 5.x, VC6-7.0 or GCC 2.9x //--------------------------------//
229 #endif // #ifndef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION //---------------//
231 } } } // End namespaces detail, iostreams, boost.
233 #include <boost/iostreams/detail/config/enable_warnings.hpp> // VC7.1 4224.
235 #endif // BOOST_IOSTREAMS_DETAIL_RESOLVE_HPP_INCLUDED