1 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
2 // (C) Copyright 2004-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 // Contains the definition of the class template
9 // boost::iostreams::detail::double_object, which is similar to compressed pair
10 // except that both members of the pair have the same type, and
11 // compression occurs only if requested using a boolean template
14 #ifndef BOOST_IOSTREAMS_DETAIL_DOUBLE_OBJECT_HPP_INCLUDED
15 #define BOOST_IOSTREAMS_DETAIL_DOUBLE_OBJECT_HPP_INCLUDED
21 #include <algorithm> // swap.
22 #include <boost/detail/workaround.hpp>
23 #include <boost/mpl/if.hpp>
24 #if BOOST_WORKAROUND(__MWERKS__, > 0x3003)
25 # include <msl_utility>
27 # include <boost/call_traits.hpp>
30 namespace boost { namespace iostreams { namespace detail {
33 class single_object_holder {
35 #if BOOST_WORKAROUND(__MWERKS__, > 0x3003)
36 typedef Metrowerks::call_traits<T> traits_type;
38 typedef boost::call_traits<T> traits_type;
40 typedef typename traits_type::param_type param_type;
41 typedef typename traits_type::reference reference;
42 typedef typename traits_type::const_reference const_reference;
43 single_object_holder() { }
44 single_object_holder(param_type t) : first_(t) { }
45 reference first() { return first_; }
46 const_reference first() const { return first_; }
47 reference second() { return first_; }
48 const_reference second() const { return first_; }
49 void swap(single_object_holder& o)
50 { std::swap(first_, o.first_); }
56 struct double_object_holder {
58 #if BOOST_WORKAROUND(__MWERKS__, > 0x3003)
59 typedef Metrowerks::call_traits<T> traits_type;
61 typedef boost::call_traits<T> traits_type;
63 typedef typename traits_type::param_type param_type;
64 typedef typename traits_type::reference reference;
65 typedef typename traits_type::const_reference const_reference;
66 double_object_holder() { }
67 double_object_holder(param_type t1, param_type t2)
68 : first_(t1), second_(t2) { }
69 reference first() { return first_; }
70 const_reference first() const { return first_; }
71 reference second() { return second_; }
72 const_reference second() const { return second_; }
73 void swap(double_object_holder& d)
75 std::swap(first_, d.first_);
76 std::swap(second_, d.second_);
82 template<typename T, typename IsDouble>
86 double_object_holder<T>,
87 single_object_holder<T>
94 double_object_holder<T>,
95 single_object_holder<T>
98 #if BOOST_WORKAROUND(__MWERKS__, > 0x3003)
99 typedef Metrowerks::call_traits<T> traits_type;
101 typedef boost::call_traits<T> traits_type;
103 typedef typename traits_type::param_type param_type;
104 typedef typename traits_type::reference reference;
105 typedef typename traits_type::const_reference const_reference;
106 double_object() : base_type() {}
107 double_object(param_type t1, param_type t2)
108 : base_type(t1, t2) { }
109 bool is_double() const { return IsDouble::value; }
112 } } } // End namespaces detail, iostreams, boost.
114 #endif // #ifndef BOOST_IOSTREAMS_DETAIL_DOUBLE_OBJECT_HPP_INCLUDED