merged tuples_subnamespace branch to main trunk

[SVN r11121]
This commit is contained in:
Jaakko Järvi
2001-09-14 07:55:58 +00:00
parent 531fb617eb
commit 5b40ff62c6
5 changed files with 330 additions and 325 deletions

View File

@ -36,15 +36,14 @@
#include "boost/type_traits/cv_traits.hpp" #include "boost/type_traits/cv_traits.hpp"
namespace boost { namespace boost {
namespace tuples {
// -- null_type -------------------------------------------------------- // -- null_type --------------------------------------------------------
struct null_type {}; struct null_type {};
// a helper function to provide a const null_type type temporary // a helper function to provide a const null_type type temporary
namespace detail { namespace detail {
namespace tuples {
inline const null_type cnull_type() { return null_type(); } inline const null_type cnull_type() { return null_type(); }
} // end tuples
} // end detail } // end detail
// - cons forward declaration ----------------------------------------------- // - cons forward declaration -----------------------------------------------
@ -60,12 +59,11 @@ template <
class tuple; class tuple;
// tuple_length forward declaration // tuple_length forward declaration
template<class T> struct tuple_length; template<class T> struct length;
namespace detail { namespace detail {
namespace tuples {
// -- generate error template, referencing to non-existing members of this // -- generate error template, referencing to non-existing members of this
// template is used to produce compilation errors intentionally // template is used to produce compilation errors intentionally
@ -108,24 +106,24 @@ struct default_arg<T&> {
}; };
// - cons getters -------------------------------------------------------- // - cons getters --------------------------------------------------------
// called: element<N>::get<RETURN_TYPE>(aTuple) // called: get_class<N>::get<RETURN_TYPE>(aTuple)
template< int N > template< int N >
struct element { struct get_class {
template<class RET, class HT, class TT > template<class RET, class HT, class TT >
inline static RET get(const cons<HT, TT>& t) inline static RET get(const cons<HT, TT>& t)
{ {
return element<N-1>::template get<RET>(t.tail); return get_class<N-1>::template get<RET>(t.tail);
} }
template<class RET, class HT, class TT > template<class RET, class HT, class TT >
inline static RET get(cons<HT, TT>& t) inline static RET get(cons<HT, TT>& t)
{ {
return element<N-1>::template get<RET>(t.tail); return get_class<N-1>::template get<RET>(t.tail);
} }
}; };
template<> template<>
struct element<0> { struct get_class<0> {
template<class RET, class HT, class TT> template<class RET, class HT, class TT>
inline static RET get(const cons<HT, TT>& t) inline static RET get(const cons<HT, TT>& t)
{ {
@ -138,25 +136,24 @@ struct element<0> {
} }
}; };
} // end of namespace tuples
} // end of namespace detail } // end of namespace detail
// -cons type accessors ---------------------------------------- // -cons type accessors ----------------------------------------
// typename tuple_element<N,T>::type gets the type of the // typename tuples::element<N,T>::type gets the type of the
// Nth element ot T, first element is at index 0 // Nth element ot T, first element is at index 0
// ------------------------------------------------------- // -------------------------------------------------------
template<int N, class T> template<int N, class T>
struct tuple_element struct element
{ {
private: private:
typedef typename T::tail_type Next; typedef typename T::tail_type Next;
public: public:
typedef typename tuple_element<N-1, Next>::type type; typedef typename element<N-1, Next>::type type;
}; };
template<class T> template<class T>
struct tuple_element<0,T> struct element<0,T>
{ {
typedef typename T::head_type type; typedef typename T::head_type type;
}; };
@ -170,7 +167,7 @@ struct tuple_element<0,T>
// (Joel de Guzman's suggestion). Rationale: get functions are part of the // (Joel de Guzman's suggestion). Rationale: get functions are part of the
// interface, so should the way to express their return types be. // interface, so should the way to express their return types be.
template <class T> struct tuple_access_traits { template <class T> struct access_traits {
typedef const T& const_type; typedef const T& const_type;
typedef T& non_const_type; typedef T& non_const_type;
@ -182,7 +179,7 @@ template <class T> struct tuple_access_traits {
// be non-volatile and const. 8.5.3. (5) // be non-volatile and const. 8.5.3. (5)
}; };
template <class T> struct tuple_access_traits<T&> { template <class T> struct access_traits<T&> {
typedef T& const_type; typedef T& const_type;
typedef T& non_const_type; typedef T& non_const_type;
@ -194,14 +191,14 @@ template <class T> struct tuple_access_traits<T&> {
// get function for non-const cons-lists, returns a reference to the element // get function for non-const cons-lists, returns a reference to the element
template<int N, class HT, class TT> template<int N, class HT, class TT>
inline typename tuple_access_traits< inline typename access_traits<
typename tuple_element<N, cons<HT, TT> >::type typename element<N, cons<HT, TT> >::type
>::non_const_type >::non_const_type
get(cons<HT, TT>& c) { get(cons<HT, TT>& c) {
return detail::tuples::element<N>::template return detail::get_class<N>::template
get< get<
typename tuple_access_traits< typename access_traits<
typename tuple_element<N, cons<HT, TT> >::type typename element<N, cons<HT, TT> >::type
>::non_const_type>(c); >::non_const_type>(c);
} }
@ -209,14 +206,14 @@ get(cons<HT, TT>& c) {
// the element. If the element is a reference, returns the reference // the element. If the element is a reference, returns the reference
// as such (that is, can return a non-const reference) // as such (that is, can return a non-const reference)
template<int N, class HT, class TT> template<int N, class HT, class TT>
inline typename tuple_access_traits< inline typename access_traits<
typename tuple_element<N, cons<HT, TT> >::type typename element<N, cons<HT, TT> >::type
>::const_type >::const_type
get(const cons<HT, TT>& c) { get(const cons<HT, TT>& c) {
return detail::tuples::element<N>::template return detail::get_class<N>::template
get< get<
typename tuple_access_traits< typename access_traits<
typename tuple_element<N, cons<HT, TT> >::type typename element<N, cons<HT, TT> >::type
>::const_type>(c); >::const_type>(c);
} }
@ -234,25 +231,25 @@ struct cons {
head_type head; head_type head;
tail_type tail; tail_type tail;
typename tuple_access_traits<head_type>::non_const_type typename access_traits<head_type>::non_const_type
get_head() { return head; } get_head() { return head; }
typename tuple_access_traits<tail_type>::non_const_type typename access_traits<tail_type>::non_const_type
get_tail() { return tail; } get_tail() { return tail; }
typename tuple_access_traits<head_type>::const_type typename access_traits<head_type>::const_type
get_head() const { return head; } get_head() const { return head; }
typename tuple_access_traits<tail_type>::const_type typename access_traits<tail_type>::const_type
get_tail() const { return tail; } get_tail() const { return tail; }
cons() : head(detail::tuples::default_arg<HT>::f()), tail() {} cons() : head(detail::default_arg<HT>::f()), tail() {}
// the argument for head is not strictly needed, but it prevents // the argument for head is not strictly needed, but it prevents
// array type elements. This is good, since array type elements // array type elements. This is good, since array type elements
// cannot be supported properly in any case (no assignment, // cannot be supported properly in any case (no assignment,
// copy works only if the tails are exactly the same type, ...) // copy works only if the tails are exactly the same type, ...)
cons(typename tuple_access_traits<head_type>::parameter_type h, cons(typename access_traits<head_type>::parameter_type h,
const tail_type& t) const tail_type& t)
: head (h), tail(t) {} : head (h), tail(t) {}
@ -261,7 +258,7 @@ struct cons {
cons( T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, cons( T1& t1, T2& t2, T3& t3, T4& t4, T5& t5,
T6& t6, T7& t7, T8& t8, T9& t9, T10& t10 ) T6& t6, T7& t7, T8& t8, T9& t9, T10& t10 )
: head (t1), : head (t1),
tail (t2, t3, t4, t5, t6, t7, t8, t9, t10, detail::tuples::cnull_type()) tail (t2, t3, t4, t5, t6, t7, t8, t9, t10, detail::cnull_type())
{} {}
template <class HT2, class TT2> template <class HT2, class TT2>
@ -280,22 +277,22 @@ struct cons {
template <class T1, class T2> template <class T1, class T2>
cons& operator=( const std::pair<T1, T2>& u ) { cons& operator=( const std::pair<T1, T2>& u ) {
BOOST_STATIC_ASSERT(tuple_length<cons>::value == 2); // check length = 2 BOOST_STATIC_ASSERT(length<cons>::value == 2); // check length = 2
head = u.first; tail.head = u.second; return *this; head = u.first; tail.head = u.second; return *this;
} }
// get member functions (non-const and const) // get member functions (non-const and const)
template <int N> template <int N>
typename tuple_access_traits< typename access_traits<
typename tuple_element<N, cons<HT, TT> >::type typename element<N, cons<HT, TT> >::type
>::non_const_type >::non_const_type
get() { get() {
return boost::get<N>(*this); // delegate to non-member get return boost::get<N>(*this); // delegate to non-member get
} }
template <int N> template <int N>
typename tuple_access_traits< typename access_traits<
typename tuple_element<N, cons<HT, TT> >::type typename element<N, cons<HT, TT> >::type
>::const_type >::const_type
get() const { get() const {
return boost::get<N>(*this); // delegate to non-member get return boost::get<N>(*this); // delegate to non-member get
@ -310,19 +307,19 @@ struct cons<HT, null_type> {
head_type head; head_type head;
typename tuple_access_traits<head_type>::non_const_type typename access_traits<head_type>::non_const_type
get_head() { return head; } get_head() { return head; }
null_type get_tail() { return null_type(); } null_type get_tail() { return null_type(); }
typename tuple_access_traits<head_type>::const_type typename access_traits<head_type>::const_type
get_head() const { return head; } get_head() const { return head; }
const null_type get_tail() const { return null_type(); } const null_type get_tail() const { return null_type(); }
cons() : head(detail::tuples::default_arg<HT>::f()) {} cons() : head(detail::default_arg<HT>::f()) {}
cons(typename tuple_access_traits<head_type>::parameter_type h, cons(typename access_traits<head_type>::parameter_type h,
const null_type& = null_type()) const null_type& = null_type())
: head (h) {} : head (h) {}
@ -344,16 +341,16 @@ struct cons<HT, null_type> {
cons& operator=(const cons& u) { head = u.head; return *this; } cons& operator=(const cons& u) { head = u.head; return *this; }
template <int N> template <int N>
typename tuple_access_traits< typename access_traits<
typename tuple_element<N, cons>::type typename element<N, cons>::type
>::non_const_type >::non_const_type
get() { get() {
return boost::get<N>(*this); return boost::get<N>(*this);
} }
template <int N> template <int N>
typename tuple_access_traits< typename access_traits<
typename tuple_element<N, cons>::type typename element<N, cons>::type
>::const_type >::const_type
get() const { get() const {
return boost::get<N>(*this); return boost::get<N>(*this);
@ -364,18 +361,17 @@ struct cons<HT, null_type> {
// templates for finding out the length of the tuple ------------------- // templates for finding out the length of the tuple -------------------
template<class T> template<class T>
struct tuple_length { struct length {
BOOST_STATIC_CONSTANT(int, value = 1 + tuple_length<typename T::tail_type>::value); BOOST_STATIC_CONSTANT(int, value = 1 + length<typename T::tail_type>::value);
}; };
template<> template<>
struct tuple_length<null_type> { struct length<null_type> {
BOOST_STATIC_CONSTANT(int, value = 0); BOOST_STATIC_CONSTANT(int, value = 0);
}; };
namespace detail { namespace detail {
namespace tuples {
// Tuple to cons mapper -------------------------------------------------- // Tuple to cons mapper --------------------------------------------------
template <class T0, class T1, class T2, class T3, class T4, template <class T0, class T1, class T2, class T3, class T4,
@ -395,7 +391,6 @@ struct map_tuple_to_cons<null_type, null_type, null_type, null_type, null_type,
typedef null_type type; typedef null_type type;
}; };
} // end tuples
} // end detail } // end detail
// ------------------------------------------------------------------- // -------------------------------------------------------------------
@ -404,37 +399,37 @@ template <class T0, class T1, class T2, class T3, class T4,
class T5, class T6, class T7, class T8, class T9> class T5, class T6, class T7, class T8, class T9>
class tuple : class tuple :
public detail::tuples::map_tuple_to_cons<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type public detail::map_tuple_to_cons<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type
{ {
public: public:
typedef typename typedef typename
detail::tuples::map_tuple_to_cons<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type inherited; detail::map_tuple_to_cons<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type inherited;
typedef typename inherited::head_type head_type; typedef typename inherited::head_type head_type;
typedef typename inherited::tail_type tail_type; typedef typename inherited::tail_type tail_type;
// tuple_access_traits<T>::parameter_type takes non-reference types as const T& // access_traits<T>::parameter_type takes non-reference types as const T&
explicit tuple( explicit tuple(
typename tuple_access_traits<T0>::parameter_type t0 typename access_traits<T0>::parameter_type t0
= detail::tuples::default_arg<T0>::f(), = detail::default_arg<T0>::f(),
typename tuple_access_traits<T1>::parameter_type t1 typename access_traits<T1>::parameter_type t1
= detail::tuples::default_arg<T1>::f(), = detail::default_arg<T1>::f(),
typename tuple_access_traits<T2>::parameter_type t2 typename access_traits<T2>::parameter_type t2
= detail::tuples::default_arg<T2>::f(), = detail::default_arg<T2>::f(),
typename tuple_access_traits<T3>::parameter_type t3 typename access_traits<T3>::parameter_type t3
= detail::tuples::default_arg<T3>::f(), = detail::default_arg<T3>::f(),
typename tuple_access_traits<T4>::parameter_type t4 typename access_traits<T4>::parameter_type t4
= detail::tuples::default_arg<T4>::f(), = detail::default_arg<T4>::f(),
typename tuple_access_traits<T5>::parameter_type t5 typename access_traits<T5>::parameter_type t5
= detail::tuples::default_arg<T5>::f(), = detail::default_arg<T5>::f(),
typename tuple_access_traits<T6>::parameter_type t6 typename access_traits<T6>::parameter_type t6
= detail::tuples::default_arg<T6>::f(), = detail::default_arg<T6>::f(),
typename tuple_access_traits<T7>::parameter_type t7 typename access_traits<T7>::parameter_type t7
= detail::tuples::default_arg<T7>::f(), = detail::default_arg<T7>::f(),
typename tuple_access_traits<T8>::parameter_type t8 typename access_traits<T8>::parameter_type t8
= detail::tuples::default_arg<T8>::f(), = detail::default_arg<T8>::f(),
typename tuple_access_traits<T9>::parameter_type t9 typename access_traits<T9>::parameter_type t9
= detail::tuples::default_arg<T9>::f()) = detail::default_arg<T9>::f())
: inherited(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) {} : inherited(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) {}
@ -449,7 +444,7 @@ public:
template <class U1, class U2> template <class U1, class U2>
tuple& operator=(const std::pair<U1, U2>& k) { tuple& operator=(const std::pair<U1, U2>& k) {
BOOST_STATIC_ASSERT(tuple_length<tuple>::value == 2);// check_length = 2 BOOST_STATIC_ASSERT(length<tuple>::value == 2);// check_length = 2
this->head = k.first; this->head = k.first;
this->tail.head = k.second; this->tail.head = k.second;
return *this; return *this;
@ -469,7 +464,6 @@ public:
// Swallows any assignment (by Doug Gregor) // Swallows any assignment (by Doug Gregor)
namespace detail { namespace detail {
namespace tuples {
struct swallow_assign { struct swallow_assign {
@ -478,12 +472,12 @@ struct swallow_assign {
return *this; return *this;
} }
}; };
} // namespace tuples
} // namespace detail } // namespace detail
// "ignore" allows tuple positions to be ignored when using "tie". // "ignore" allows tuple positions to be ignored when using "tie".
namespace { namespace {
detail::tuples::swallow_assign ignore; detail::swallow_assign ignore;
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -530,7 +524,7 @@ struct make_tuple_traits {
template<class T> template<class T>
struct make_tuple_traits<T&> { struct make_tuple_traits<T&> {
typedef typename typedef typename
detail::tuples::generate_error<T&>:: detail::generate_error<T&>::
do_not_use_with_reference_type error; do_not_use_with_reference_type error;
}; };
@ -570,7 +564,6 @@ struct make_tuple_traits<const reference_wrapper<T> >{
namespace detail { namespace detail {
namespace tuples {
// a helper traits to make the make_tuple functions shorter (Vesa Karvonen's // a helper traits to make the make_tuple functions shorter (Vesa Karvonen's
// suggestion) // suggestion)
@ -594,7 +587,6 @@ struct make_tuple_mapper {
typename make_tuple_traits<T9>::type> type; typename make_tuple_traits<T9>::type> type;
}; };
} // end tuples
} // end detail } // end detail
// -make_tuple function templates ----------------------------------- // -make_tuple function templates -----------------------------------
@ -603,85 +595,85 @@ inline tuple<> make_tuple() {
} }
template<class T0> template<class T0>
inline typename boost::detail::tuples::make_tuple_mapper<T0>::type inline typename detail::make_tuple_mapper<T0>::type
make_tuple(const T0& t0) { make_tuple(const T0& t0) {
return typename boost::detail::tuples::make_tuple_mapper<T0>::type(t0); return typename detail::make_tuple_mapper<T0>::type(t0);
} }
template<class T0, class T1> template<class T0, class T1>
inline typename boost::detail::tuples::make_tuple_mapper<T0, T1>::type inline typename detail::make_tuple_mapper<T0, T1>::type
make_tuple(const T0& t0, const T1& t1) { make_tuple(const T0& t0, const T1& t1) {
return typename boost::detail::tuples::make_tuple_mapper<T0, T1>::type(t0, t1); return typename detail::make_tuple_mapper<T0, T1>::type(t0, t1);
} }
template<class T0, class T1, class T2> template<class T0, class T1, class T2>
inline typename boost::detail::tuples::make_tuple_mapper<T0, T1, T2>::type inline typename detail::make_tuple_mapper<T0, T1, T2>::type
make_tuple(const T0& t0, const T1& t1, const T2& t2) { make_tuple(const T0& t0, const T1& t1, const T2& t2) {
return typename boost::detail::tuples::make_tuple_mapper<T0, T1, T2>::type(t0, t1, t2); return typename detail::make_tuple_mapper<T0, T1, T2>::type(t0, t1, t2);
} }
template<class T0, class T1, class T2, class T3> template<class T0, class T1, class T2, class T3>
inline typename boost::detail::tuples::make_tuple_mapper<T0, T1, T2, T3>::type inline typename detail::make_tuple_mapper<T0, T1, T2, T3>::type
make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3) { make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3) {
return typename boost::detail::tuples::make_tuple_mapper<T0, T1, T2, T3>::type return typename detail::make_tuple_mapper<T0, T1, T2, T3>::type
(t0, t1, t2, t3); (t0, t1, t2, t3);
} }
template<class T0, class T1, class T2, class T3, class T4> template<class T0, class T1, class T2, class T3, class T4>
inline typename boost::detail::tuples::make_tuple_mapper<T0, T1, T2, T3, T4>::type inline typename detail::make_tuple_mapper<T0, T1, T2, T3, T4>::type
make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
const T4& t4) { const T4& t4) {
return typename boost::detail::tuples::make_tuple_mapper<T0, T1, T2, T3, T4>::type return typename detail::make_tuple_mapper<T0, T1, T2, T3, T4>::type
(t0, t1, t2, t3, t4); (t0, t1, t2, t3, t4);
} }
template<class T0, class T1, class T2, class T3, class T4, class T5> template<class T0, class T1, class T2, class T3, class T4, class T5>
inline typename boost::detail::tuples::make_tuple_mapper<T0, T1, T2, T3, T4, T5>::type inline typename detail::make_tuple_mapper<T0, T1, T2, T3, T4, T5>::type
make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
const T4& t4, const T5& t5) { const T4& t4, const T5& t5) {
return typename boost::detail::tuples::make_tuple_mapper<T0, T1, T2, T3, T4, T5>::type return typename detail::make_tuple_mapper<T0, T1, T2, T3, T4, T5>::type
(t0, t1, t2, t3, t4, t5); (t0, t1, t2, t3, t4, t5);
} }
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> template<class T0, class T1, class T2, class T3, class T4, class T5, class T6>
inline typename boost::detail::tuples::make_tuple_mapper<T0, T1, T2, T3, T4, T5, T6>::type inline typename detail::make_tuple_mapper<T0, T1, T2, T3, T4, T5, T6>::type
make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
const T4& t4, const T5& t5, const T6& t6) { const T4& t4, const T5& t5, const T6& t6) {
return typename boost::detail::tuples::make_tuple_mapper return typename detail::make_tuple_mapper
<T0, T1, T2, T3, T4, T5, T6>::type <T0, T1, T2, T3, T4, T5, T6>::type
(t0, t1, t2, t3, t4, t5, t6); (t0, t1, t2, t3, t4, t5, t6);
} }
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6, template<class T0, class T1, class T2, class T3, class T4, class T5, class T6,
class T7> class T7>
inline typename boost::detail::tuples::make_tuple_mapper<T0, T1, T2, T3, T4, T5, T6, T7>::type inline typename detail::make_tuple_mapper<T0, T1, T2, T3, T4, T5, T6, T7>::type
make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
const T4& t4, const T5& t5, const T6& t6, const T7& t7) { const T4& t4, const T5& t5, const T6& t6, const T7& t7) {
return typename boost::detail::tuples::make_tuple_mapper return typename detail::make_tuple_mapper
<T0, T1, T2, T3, T4, T5, T6, T7>::type <T0, T1, T2, T3, T4, T5, T6, T7>::type
(t0, t1, t2, t3, t4, t5, t6, t7); (t0, t1, t2, t3, t4, t5, t6, t7);
} }
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6, template<class T0, class T1, class T2, class T3, class T4, class T5, class T6,
class T7, class T8> class T7, class T8>
inline typename boost::detail::tuples::make_tuple_mapper inline typename detail::make_tuple_mapper
<T0, T1, T2, T3, T4, T5, T6, T7, T8>::type <T0, T1, T2, T3, T4, T5, T6, T7, T8>::type
make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T4& t4, const T5& t5, const T6& t6, const T7& t7,
const T8& t8) { const T8& t8) {
return typename boost::detail::tuples::make_tuple_mapper return typename detail::make_tuple_mapper
<T0, T1, T2, T3, T4, T5, T6, T7, T8>::type <T0, T1, T2, T3, T4, T5, T6, T7, T8>::type
(t0, t1, t2, t3, t4, t5, t6, t7, t8); (t0, t1, t2, t3, t4, t5, t6, t7, t8);
} }
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6, template<class T0, class T1, class T2, class T3, class T4, class T5, class T6,
class T7, class T8, class T9> class T7, class T8, class T9>
inline typename boost::detail::tuples::make_tuple_mapper inline typename detail::make_tuple_mapper
<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type <T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type
make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T4& t4, const T5& t5, const T6& t6, const T7& t7,
const T8& t8, const T9& t9) { const T8& t8, const T9& t9) {
return typename boost::detail::tuples::make_tuple_mapper return typename detail::make_tuple_mapper
<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type <T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type
(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9); (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9);
} }
@ -753,6 +745,7 @@ tie(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7, T8& t8,
(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10); (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10);
} }
} // end of namespace tuples
} // end of namespace boost } // end of namespace boost

View File

@ -41,6 +41,7 @@
#endif #endif
namespace boost { namespace boost {
namespace tuples {
// null_type denotes the end of a list built with "cons" // null_type denotes the end of a list built with "cons"
struct null_type struct null_type
@ -53,7 +54,7 @@ namespace boost {
inline const null_type cnull_type() { return null_type(); } inline const null_type cnull_type() { return null_type(); }
namespace detail { namespace detail {
namespace tuples {
// Takes a pointer and routes all assignments to whatever it points to // Takes a pointer and routes all assignments to whatever it points to
template<typename T> template<typename T>
struct assign_to_pointee struct assign_to_pointee
@ -82,7 +83,6 @@ namespace boost {
} }
}; };
} // end of namespace tuples
} // end of namespace detail } // end of namespace detail
// cons builds a heterogenous list of types // cons builds a heterogenous list of types
@ -103,9 +103,9 @@ namespace boost {
typename boost::add_reference<const tail_type>::type get_tail() const { return tail; } typename boost::add_reference<const tail_type>::type get_tail() const { return tail; }
#if defined BOOST_MSVC #if defined BOOST_MSVC
template<typename T> template<typename Tail>
explicit cons(const head_type& h /* = head_type() */, // causes MSVC 6.5 to barf. explicit cons(const head_type& h /* = head_type() */, // causes MSVC 6.5 to barf.
const T& t) : head(h), tail(t.head, t.tail) const Tail& t) : head(h), tail(t.head, t.tail)
{ {
} }
@ -116,8 +116,8 @@ namespace boost {
#else #else
template<typename T> template<typename T>
explicit cons(const head_type& h = head_type(), explicit cons(const head_type& h, const T& t) :
const T& t) : head(h), tail(t.head, t.tail) head(h), tail(t.head, t.tail)
{ {
} }
@ -139,7 +139,7 @@ namespace boost {
}; };
namespace detail { namespace detail {
namespace tuples {
// Determines if the parameter is null_type // Determines if the parameter is null_type
template<typename T> struct is_null_type { enum { RET = 0 }; }; template<typename T> struct is_null_type { enum { RET = 0 }; };
template<> struct is_null_type<null_type> { enum { RET = 1 }; }; template<> struct is_null_type<null_type> { enum { RET = 1 }; };
@ -176,16 +176,16 @@ namespace boost {
> >
struct map_tuple_to_cons struct map_tuple_to_cons
{ {
typedef typename detail::tuples::build_cons<T10, null_type >::RET cons10; typedef typename detail::build_cons<T10, null_type >::RET cons10;
typedef typename detail::tuples::build_cons<T9, cons10>::RET cons9; typedef typename detail::build_cons<T9, cons10>::RET cons9;
typedef typename detail::tuples::build_cons<T8, cons9>::RET cons8; typedef typename detail::build_cons<T8, cons9>::RET cons8;
typedef typename detail::tuples::build_cons<T7, cons8>::RET cons7; typedef typename detail::build_cons<T7, cons8>::RET cons7;
typedef typename detail::tuples::build_cons<T6, cons7>::RET cons6; typedef typename detail::build_cons<T6, cons7>::RET cons6;
typedef typename detail::tuples::build_cons<T5, cons6>::RET cons5; typedef typename detail::build_cons<T5, cons6>::RET cons5;
typedef typename detail::tuples::build_cons<T4, cons5>::RET cons4; typedef typename detail::build_cons<T4, cons5>::RET cons4;
typedef typename detail::tuples::build_cons<T3, cons4>::RET cons3; typedef typename detail::build_cons<T3, cons4>::RET cons3;
typedef typename detail::tuples::build_cons<T2, cons3>::RET cons2; typedef typename detail::build_cons<T2, cons3>::RET cons2;
typedef typename detail::tuples::build_cons<T1, cons2>::RET cons1; typedef typename detail::build_cons<T1, cons2>::RET cons1;
}; };
// Workaround the lack of partial specialization in some compilers // Workaround the lack of partial specialization in some compilers
@ -213,15 +213,16 @@ namespace boost {
typedef typename Tuple::head_type RET; typedef typename Tuple::head_type RET;
}; };
}; };
} // detail
} // tuples } // namespace detail
// Return the Nth type of the given Tuple // Return the Nth type of the given Tuple
template<int N, typename Tuple> template<int N, typename Tuple>
struct tuple_element struct element
{ {
private: private:
typedef detail::tuples::_element_type<N> nth_type; typedef detail::_element_type<N> nth_type;
public: public:
typedef typename nth_type::template inner<Tuple>::RET RET; typedef typename nth_type::template inner<Tuple>::RET RET;
@ -229,13 +230,13 @@ namespace boost {
}; };
namespace detail { namespace detail {
namespace tuples {
// Return a reference to the Nth type of the given Tuple // Return a reference to the Nth type of the given Tuple
template<int N, typename Tuple> template<int N, typename Tuple>
struct tuple_element_ref struct element_ref
{ {
private: private:
typedef typename tuple_element<N, Tuple>::RET elt_type; typedef typename element<N, Tuple>::RET elt_type;
public: public:
typedef typename add_reference<elt_type>::type RET; typedef typename add_reference<elt_type>::type RET;
@ -244,53 +245,56 @@ namespace boost {
// Return a const reference to the Nth type of the given Tuple // Return a const reference to the Nth type of the given Tuple
template<int N, typename Tuple> template<int N, typename Tuple>
struct tuple_element_const_ref struct element_const_ref
{ {
private: private:
typedef typename tuple_element<N, Tuple>::RET elt_type; typedef typename element<N, Tuple>::RET elt_type;
public: public:
typedef typename add_reference<const elt_type>::type RET; typedef typename add_reference<const elt_type>::type RET;
typedef RET type; typedef RET type;
}; };
}
} } // namespace detail
// Get length of this tuple // Get length of this tuple
template<typename Tuple> template<typename Tuple>
struct tuple_length struct length
{ {
enum { value = 1 + tuple_length<typename Tuple::tail_type>::value }; BOOST_STATIC_CONSTANT(int, value = 1 + length<typename Tuple::tail_type>::value);
}; };
template<> template<>
struct tuple_length<null_type> struct length<null_type>
{ {
enum { value = 0 }; BOOST_STATIC_CONSTANT(int, value = 0);
}; };
namespace detail {
// Reference the Nth element in a tuple and retrieve it with "get" // Reference the Nth element in a tuple and retrieve it with "get"
template<int N> template<int N>
struct element struct get_class
{ {
template<typename Head, typename Tail> template<typename Head, typename Tail>
static inline static inline
typename detail::tuples::tuple_element_ref<N, cons<Head, Tail> >::RET typename detail::element_ref<N, cons<Head, Tail> >::RET
get(cons<Head, Tail>& t) get(cons<Head, Tail>& t)
{ {
return element<N-1>::get(t.tail); return get_class<N-1>::get(t.tail);
} }
template<typename Head, typename Tail> template<typename Head, typename Tail>
static inline static inline
typename detail::tuples::tuple_element_const_ref<N, cons<Head, Tail> >::RET typename detail::element_const_ref<N, cons<Head, Tail> >::RET
get(const cons<Head, Tail>& t) get(const cons<Head, Tail>& t)
{ {
return element<N-1>::get(t.tail); return get_class<N-1>::get(t.tail);
} }
}; };
template<> template<>
struct element<0> struct get_class<0>
{ {
template<typename Head, typename Tail> template<typename Head, typename Tail>
static inline static inline
@ -309,6 +313,8 @@ namespace boost {
} }
}; };
} // namespace detail
// tuple class // tuple class
template< template<
typename T1, typename T1,
@ -323,10 +329,10 @@ namespace boost {
typename T10 = null_type typename T10 = null_type
> >
class tuple : class tuple :
public detail::tuples::map_tuple_to_cons<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>::cons1 public detail::map_tuple_to_cons<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>::cons1
{ {
private: private:
typedef detail::tuples::map_tuple_to_cons<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> mapped_tuple; typedef detail::map_tuple_to_cons<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> mapped_tuple;
typedef typename mapped_tuple::cons10 cons10; typedef typename mapped_tuple::cons10 cons10;
typedef typename mapped_tuple::cons9 cons9; typedef typename mapped_tuple::cons9 cons9;
typedef typename mapped_tuple::cons8 cons8; typedef typename mapped_tuple::cons8 cons8;
@ -380,22 +386,23 @@ namespace boost {
}; };
namespace detail { namespace detail {
namespace tuples {
template<int N> struct workaround_holder {}; template<int N> struct workaround_holder {};
}}
} // namespace detail
template<int N, typename Head, typename Tail> template<int N, typename Head, typename Tail>
typename detail::tuples::tuple_element_ref<N, cons<Head, Tail> >::RET typename detail::element_ref<N, cons<Head, Tail> >::RET
get(cons<Head, Tail>& t, detail::tuples::workaround_holder<N>* = 0) get(cons<Head, Tail>& t, detail::workaround_holder<N>* = 0)
{ {
return element<N>::get(t); return detail::get_class<N>::get(t);
} }
template<int N, typename Head, typename Tail> template<int N, typename Head, typename Tail>
typename detail::tuples::tuple_element_const_ref<N, cons<Head, Tail> >::RET typename detail::element_const_ref<N, cons<Head, Tail> >::RET
get(const cons<Head, Tail>& t, detail::tuples::workaround_holder<N>* = 0) get(const cons<Head, Tail>& t, detail::workaround_holder<N>* = 0)
{ {
return element<N>::get(t); return detail::get_class<N>::get(t);
} }
// Make a tuple // Make a tuple
@ -491,185 +498,186 @@ namespace boost {
// Tie variables into a tuple // Tie variables into a tuple
template<typename T1> template<typename T1>
inline inline
tuple<detail::tuples::assign_to_pointee<T1> > tuple<detail::assign_to_pointee<T1> >
tie(T1& t1) tie(T1& t1)
{ {
return make_tuple(detail::tuples::assign_to_pointee<T1>(&t1)); return make_tuple(detail::assign_to_pointee<T1>(&t1));
} }
// Tie variables into a tuple // Tie variables into a tuple
template<typename T1, typename T2> template<typename T1, typename T2>
inline inline
tuple<detail::tuples::assign_to_pointee<T1>, tuple<detail::assign_to_pointee<T1>,
detail::tuples::assign_to_pointee<T2> > detail::assign_to_pointee<T2> >
tie(T1& t1, T2& t2) tie(T1& t1, T2& t2)
{ {
return make_tuple(detail::tuples::assign_to_pointee<T1>(&t1), return make_tuple(detail::assign_to_pointee<T1>(&t1),
detail::tuples::assign_to_pointee<T2>(&t2)); detail::assign_to_pointee<T2>(&t2));
} }
// Tie variables into a tuple // Tie variables into a tuple
template<typename T1, typename T2, typename T3> template<typename T1, typename T2, typename T3>
inline inline
tuple<detail::tuples::assign_to_pointee<T1>, tuple<detail::assign_to_pointee<T1>,
detail::tuples::assign_to_pointee<T2>, detail::assign_to_pointee<T2>,
detail::tuples::assign_to_pointee<T3> > detail::assign_to_pointee<T3> >
tie(T1& t1, T2& t2, T3& t3) tie(T1& t1, T2& t2, T3& t3)
{ {
return make_tuple(detail::tuples::assign_to_pointee<T1>(&t1), return make_tuple(detail::assign_to_pointee<T1>(&t1),
detail::tuples::assign_to_pointee<T2>(&t2), detail::assign_to_pointee<T2>(&t2),
detail::tuples::assign_to_pointee<T3>(&t3)); detail::assign_to_pointee<T3>(&t3));
} }
// Tie variables into a tuple // Tie variables into a tuple
template<typename T1, typename T2, typename T3, typename T4> template<typename T1, typename T2, typename T3, typename T4>
inline inline
tuple<detail::tuples::assign_to_pointee<T1>, tuple<detail::assign_to_pointee<T1>,
detail::tuples::assign_to_pointee<T2>, detail::assign_to_pointee<T2>,
detail::tuples::assign_to_pointee<T3>, detail::assign_to_pointee<T3>,
detail::tuples::assign_to_pointee<T4> > detail::assign_to_pointee<T4> >
tie(T1& t1, T2& t2, T3& t3, T4& t4) tie(T1& t1, T2& t2, T3& t3, T4& t4)
{ {
return make_tuple(detail::tuples::assign_to_pointee<T1>(&t1), return make_tuple(detail::assign_to_pointee<T1>(&t1),
detail::tuples::assign_to_pointee<T2>(&t2), detail::assign_to_pointee<T2>(&t2),
detail::tuples::assign_to_pointee<T3>(&t3), detail::assign_to_pointee<T3>(&t3),
detail::tuples::assign_to_pointee<T4>(&t4)); detail::assign_to_pointee<T4>(&t4));
} }
// Tie variables into a tuple // Tie variables into a tuple
template<typename T1, typename T2, typename T3, typename T4, typename T5> template<typename T1, typename T2, typename T3, typename T4, typename T5>
inline inline
tuple<detail::tuples::assign_to_pointee<T1>, tuple<detail::assign_to_pointee<T1>,
detail::tuples::assign_to_pointee<T2>, detail::assign_to_pointee<T2>,
detail::tuples::assign_to_pointee<T3>, detail::assign_to_pointee<T3>,
detail::tuples::assign_to_pointee<T4>, detail::assign_to_pointee<T4>,
detail::tuples::assign_to_pointee<T5> > detail::assign_to_pointee<T5> >
tie(T1& t1, T2& t2, T3& t3, T4& t4, T5 &t5) tie(T1& t1, T2& t2, T3& t3, T4& t4, T5 &t5)
{ {
return make_tuple(detail::tuples::assign_to_pointee<T1>(&t1), return make_tuple(detail::assign_to_pointee<T1>(&t1),
detail::tuples::assign_to_pointee<T2>(&t2), detail::assign_to_pointee<T2>(&t2),
detail::tuples::assign_to_pointee<T3>(&t3), detail::assign_to_pointee<T3>(&t3),
detail::tuples::assign_to_pointee<T4>(&t4), detail::assign_to_pointee<T4>(&t4),
detail::tuples::assign_to_pointee<T5>(&t5)); detail::assign_to_pointee<T5>(&t5));
} }
// Tie variables into a tuple // Tie variables into a tuple
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6> template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
inline inline
tuple<detail::tuples::assign_to_pointee<T1>, tuple<detail::assign_to_pointee<T1>,
detail::tuples::assign_to_pointee<T2>, detail::assign_to_pointee<T2>,
detail::tuples::assign_to_pointee<T3>, detail::assign_to_pointee<T3>,
detail::tuples::assign_to_pointee<T4>, detail::assign_to_pointee<T4>,
detail::tuples::assign_to_pointee<T5>, detail::assign_to_pointee<T5>,
detail::tuples::assign_to_pointee<T6> > detail::assign_to_pointee<T6> >
tie(T1& t1, T2& t2, T3& t3, T4& t4, T5 &t5, T6 &t6) tie(T1& t1, T2& t2, T3& t3, T4& t4, T5 &t5, T6 &t6)
{ {
return make_tuple(detail::tuples::assign_to_pointee<T1>(&t1), return make_tuple(detail::assign_to_pointee<T1>(&t1),
detail::tuples::assign_to_pointee<T2>(&t2), detail::assign_to_pointee<T2>(&t2),
detail::tuples::assign_to_pointee<T3>(&t3), detail::assign_to_pointee<T3>(&t3),
detail::tuples::assign_to_pointee<T4>(&t4), detail::assign_to_pointee<T4>(&t4),
detail::tuples::assign_to_pointee<T6>(&t5), detail::assign_to_pointee<T6>(&t5),
detail::tuples::assign_to_pointee<T5>(&t6)); detail::assign_to_pointee<T5>(&t6));
} }
// Tie variables into a tuple // Tie variables into a tuple
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
inline inline
tuple<detail::tuples::assign_to_pointee<T1>, tuple<detail::assign_to_pointee<T1>,
detail::tuples::assign_to_pointee<T2>, detail::assign_to_pointee<T2>,
detail::tuples::assign_to_pointee<T3>, detail::assign_to_pointee<T3>,
detail::tuples::assign_to_pointee<T4>, detail::assign_to_pointee<T4>,
detail::tuples::assign_to_pointee<T5>, detail::assign_to_pointee<T5>,
detail::tuples::assign_to_pointee<T6>, detail::assign_to_pointee<T6>,
detail::tuples::assign_to_pointee<T7> > detail::assign_to_pointee<T7> >
tie(T1& t1, T2& t2, T3& t3, T4& t4, T5 &t5, T6 &t6, T7 &t7) tie(T1& t1, T2& t2, T3& t3, T4& t4, T5 &t5, T6 &t6, T7 &t7)
{ {
return make_tuple(detail::tuples::assign_to_pointee<T1>(&t1), return make_tuple(detail::assign_to_pointee<T1>(&t1),
detail::tuples::assign_to_pointee<T2>(&t2), detail::assign_to_pointee<T2>(&t2),
detail::tuples::assign_to_pointee<T3>(&t3), detail::assign_to_pointee<T3>(&t3),
detail::tuples::assign_to_pointee<T4>(&t4), detail::assign_to_pointee<T4>(&t4),
detail::tuples::assign_to_pointee<T5>(&t5), detail::assign_to_pointee<T5>(&t5),
detail::tuples::assign_to_pointee<T6>(&t6), detail::assign_to_pointee<T6>(&t6),
detail::tuples::assign_to_pointee<T7>(&t7)); detail::assign_to_pointee<T7>(&t7));
} }
// Tie variables into a tuple // Tie variables into a tuple
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
inline inline
tuple<detail::tuples::assign_to_pointee<T1>, tuple<detail::assign_to_pointee<T1>,
detail::tuples::assign_to_pointee<T2>, detail::assign_to_pointee<T2>,
detail::tuples::assign_to_pointee<T3>, detail::assign_to_pointee<T3>,
detail::tuples::assign_to_pointee<T4>, detail::assign_to_pointee<T4>,
detail::tuples::assign_to_pointee<T5>, detail::assign_to_pointee<T5>,
detail::tuples::assign_to_pointee<T6>, detail::assign_to_pointee<T6>,
detail::tuples::assign_to_pointee<T7>, detail::assign_to_pointee<T7>,
detail::tuples::assign_to_pointee<T8> > detail::assign_to_pointee<T8> >
tie(T1& t1, T2& t2, T3& t3, T4& t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8) tie(T1& t1, T2& t2, T3& t3, T4& t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8)
{ {
return make_tuple(detail::tuples::assign_to_pointee<T1>(&t1), return make_tuple(detail::assign_to_pointee<T1>(&t1),
detail::tuples::assign_to_pointee<T2>(&t2), detail::assign_to_pointee<T2>(&t2),
detail::tuples::assign_to_pointee<T3>(&t3), detail::assign_to_pointee<T3>(&t3),
detail::tuples::assign_to_pointee<T4>(&t4), detail::assign_to_pointee<T4>(&t4),
detail::tuples::assign_to_pointee<T5>(&t5), detail::assign_to_pointee<T5>(&t5),
detail::tuples::assign_to_pointee<T6>(&t6), detail::assign_to_pointee<T6>(&t6),
detail::tuples::assign_to_pointee<T7>(&t7), detail::assign_to_pointee<T7>(&t7),
detail::tuples::assign_to_pointee<T8>(&t8)); detail::assign_to_pointee<T8>(&t8));
} }
// Tie variables into a tuple // Tie variables into a tuple
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9> template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
inline inline
tuple<detail::tuples::assign_to_pointee<T1>, tuple<detail::assign_to_pointee<T1>,
detail::tuples::assign_to_pointee<T2>, detail::assign_to_pointee<T2>,
detail::tuples::assign_to_pointee<T3>, detail::assign_to_pointee<T3>,
detail::tuples::assign_to_pointee<T4>, detail::assign_to_pointee<T4>,
detail::tuples::assign_to_pointee<T5>, detail::assign_to_pointee<T5>,
detail::tuples::assign_to_pointee<T6>, detail::assign_to_pointee<T6>,
detail::tuples::assign_to_pointee<T7>, detail::assign_to_pointee<T7>,
detail::tuples::assign_to_pointee<T8>, detail::assign_to_pointee<T8>,
detail::tuples::assign_to_pointee<T9> > detail::assign_to_pointee<T9> >
tie(T1& t1, T2& t2, T3& t3, T4& t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8, T9 &t9) tie(T1& t1, T2& t2, T3& t3, T4& t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8, T9 &t9)
{ {
return make_tuple(detail::tuples::assign_to_pointee<T1>(&t1), return make_tuple(detail::assign_to_pointee<T1>(&t1),
detail::tuples::assign_to_pointee<T2>(&t2), detail::assign_to_pointee<T2>(&t2),
detail::tuples::assign_to_pointee<T3>(&t3), detail::assign_to_pointee<T3>(&t3),
detail::tuples::assign_to_pointee<T4>(&t4), detail::assign_to_pointee<T4>(&t4),
detail::tuples::assign_to_pointee<T5>(&t5), detail::assign_to_pointee<T5>(&t5),
detail::tuples::assign_to_pointee<T6>(&t6), detail::assign_to_pointee<T6>(&t6),
detail::tuples::assign_to_pointee<T7>(&t7), detail::assign_to_pointee<T7>(&t7),
detail::tuples::assign_to_pointee<T8>(&t8), detail::assign_to_pointee<T8>(&t8),
detail::tuples::assign_to_pointee<T9>(&t9)); detail::assign_to_pointee<T9>(&t9));
} }
// Tie variables into a tuple // Tie variables into a tuple
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10> template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10>
inline inline
tuple<detail::tuples::assign_to_pointee<T1>, tuple<detail::assign_to_pointee<T1>,
detail::tuples::assign_to_pointee<T2>, detail::assign_to_pointee<T2>,
detail::tuples::assign_to_pointee<T3>, detail::assign_to_pointee<T3>,
detail::tuples::assign_to_pointee<T4>, detail::assign_to_pointee<T4>,
detail::tuples::assign_to_pointee<T5>, detail::assign_to_pointee<T5>,
detail::tuples::assign_to_pointee<T6>, detail::assign_to_pointee<T6>,
detail::tuples::assign_to_pointee<T7>, detail::assign_to_pointee<T7>,
detail::tuples::assign_to_pointee<T8>, detail::assign_to_pointee<T8>,
detail::tuples::assign_to_pointee<T9>, detail::assign_to_pointee<T9>,
detail::tuples::assign_to_pointee<T10> > detail::assign_to_pointee<T10> >
tie(T1& t1, T2& t2, T3& t3, T4& t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8, T9 &t9, T10 &t10) tie(T1& t1, T2& t2, T3& t3, T4& t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8, T9 &t9, T10 &t10)
{ {
return make_tuple(detail::tuples::assign_to_pointee<T1>(&t1), return make_tuple(detail::assign_to_pointee<T1>(&t1),
detail::tuples::assign_to_pointee<T2>(&t2), detail::assign_to_pointee<T2>(&t2),
detail::tuples::assign_to_pointee<T3>(&t3), detail::assign_to_pointee<T3>(&t3),
detail::tuples::assign_to_pointee<T4>(&t4), detail::assign_to_pointee<T4>(&t4),
detail::tuples::assign_to_pointee<T5>(&t5), detail::assign_to_pointee<T5>(&t5),
detail::tuples::assign_to_pointee<T6>(&t6), detail::assign_to_pointee<T6>(&t6),
detail::tuples::assign_to_pointee<T7>(&t7), detail::assign_to_pointee<T7>(&t7),
detail::tuples::assign_to_pointee<T8>(&t8), detail::assign_to_pointee<T8>(&t8),
detail::tuples::assign_to_pointee<T9>(&t9), detail::assign_to_pointee<T9>(&t9),
detail::tuples::assign_to_pointee<T10>(&t10)); detail::assign_to_pointee<T10>(&t10));
} }
// "ignore" allows tuple positions to be ignored when using "tie". // "ignore" allows tuple positions to be ignored when using "tie".
namespace { namespace {
detail::tuples::swallow_assign ignore; detail::swallow_assign ignore;
} }
} // namespace tuples
} // namespace boost } // namespace boost
#endif // BOOST_TUPLE_BASIC_NO_PARTIAL_SPEC_HPP #endif // BOOST_TUPLE_BASIC_NO_PARTIAL_SPEC_HPP

View File

@ -32,5 +32,14 @@
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
namespace boost {
using tuples::tuple;
using tuples::make_tuple;
using tuples::tie;
using tuples::get;
} // end namespace boost
#endif // BOOST_TUPLE_HPP #endif // BOOST_TUPLE_HPP

View File

@ -38,6 +38,7 @@
namespace boost { namespace boost {
namespace tuples {
inline bool operator==(const null_type&, const null_type&) { return true; } inline bool operator==(const null_type&, const null_type&) { return true; }
inline bool operator>=(const null_type&, const null_type&) { return true; } inline bool operator>=(const null_type&, const null_type&) { return true; }
@ -48,7 +49,6 @@ inline bool operator>(const null_type&, const null_type&) { return false; }
namespace detail { namespace detail {
namespace tuples {
// comparison operators check statically the length of its operands and // comparison operators check statically the length of its operands and
// delegate the comparing task to the following functions. Hence // delegate the comparing task to the following functions. Hence
// the static check is only made once (should help the compiler). // the static check is only made once (should help the compiler).
@ -107,7 +107,6 @@ inline bool gte(const T1& lhs, const T2& rhs) {
template<> template<>
inline bool gte<null_type,null_type>(const null_type&, const null_type&) { return true; } inline bool gte<null_type,null_type>(const null_type&, const null_type&) { return true; }
} // end of namespace tuples
} // end of namespace detail } // end of namespace detail
@ -116,10 +115,10 @@ inline bool gte<null_type,null_type>(const null_type&, const null_type&) { retur
template<class T1, class T2, class S1, class S2> template<class T1, class T2, class S1, class S2>
inline bool operator==(const cons<T1, T2>& lhs, const cons<S1, S2>& rhs) inline bool operator==(const cons<T1, T2>& lhs, const cons<S1, S2>& rhs)
{ {
// check that tuple_lengths are equal // check that tuple lengths are equal
BOOST_STATIC_ASSERT(tuple_length<T2>::value == tuple_length<S2>::value); BOOST_STATIC_ASSERT(length<T2>::value == length<S2>::value);
return detail::tuples::eq(lhs, rhs); return detail::eq(lhs, rhs);
} }
// not equal ----- // not equal -----
@ -128,52 +127,53 @@ template<class T1, class T2, class S1, class S2>
inline bool operator!=(const cons<T1, T2>& lhs, const cons<S1, S2>& rhs) inline bool operator!=(const cons<T1, T2>& lhs, const cons<S1, S2>& rhs)
{ {
// check that tuple_lengths are equal // check that tuple lengths are equal
BOOST_STATIC_ASSERT(tuple_length<T2>::value == tuple_length<S2>::value); BOOST_STATIC_ASSERT(length<T2>::value == length<S2>::value);
return detail::tuples::neq(lhs, rhs); return detail::neq(lhs, rhs);
} }
// < // <
template<class T1, class T2, class S1, class S2> template<class T1, class T2, class S1, class S2>
inline bool operator<(const cons<T1, T2>& lhs, const cons<S1, S2>& rhs) inline bool operator<(const cons<T1, T2>& lhs, const cons<S1, S2>& rhs)
{ {
// check that tuple_lengths are equal // check that tuple lengths are equal
BOOST_STATIC_ASSERT(tuple_length<T2>::value == tuple_length<S2>::value); BOOST_STATIC_ASSERT(length<T2>::value == length<S2>::value);
return detail::tuples::lt(lhs, rhs); return detail::lt(lhs, rhs);
} }
// > // >
template<class T1, class T2, class S1, class S2> template<class T1, class T2, class S1, class S2>
inline bool operator>(const cons<T1, T2>& lhs, const cons<S1, S2>& rhs) inline bool operator>(const cons<T1, T2>& lhs, const cons<S1, S2>& rhs)
{ {
// check that tuple_lengths are equal // check that tuple lengths are equal
BOOST_STATIC_ASSERT(tuple_length<T2>::value == tuple_length<S2>::value); BOOST_STATIC_ASSERT(length<T2>::value == length<S2>::value);
return detail::tuples::gt(lhs, rhs); return detail::gt(lhs, rhs);
} }
// <= // <=
template<class T1, class T2, class S1, class S2> template<class T1, class T2, class S1, class S2>
inline bool operator<=(const cons<T1, T2>& lhs, const cons<S1, S2>& rhs) inline bool operator<=(const cons<T1, T2>& lhs, const cons<S1, S2>& rhs)
{ {
// check that tuple_lengths are equal // check that tuple lengths are equal
BOOST_STATIC_ASSERT(tuple_length<T2>::value == tuple_length<S2>::value); BOOST_STATIC_ASSERT(length<T2>::value == length<S2>::value);
return detail::tuples::lte(lhs, rhs); return detail::lte(lhs, rhs);
} }
// >= // >=
template<class T1, class T2, class S1, class S2> template<class T1, class T2, class S1, class S2>
inline bool operator>=(const cons<T1, T2>& lhs, const cons<S1, S2>& rhs) inline bool operator>=(const cons<T1, T2>& lhs, const cons<S1, S2>& rhs)
{ {
// check that tuple_lengths are equal // check that tuple lengths are equal
BOOST_STATIC_ASSERT(tuple_length<T2>::value == tuple_length<S2>::value); BOOST_STATIC_ASSERT(length<T2>::value == length<S2>::value);
return detail::tuples::gte(lhs, rhs); return detail::gte(lhs, rhs);
} }
} // end of namespace tuples
} // end of namespace boost } // end of namespace boost

View File

@ -39,9 +39,9 @@
namespace boost { namespace boost {
namespace tuples {
namespace detail { namespace detail {
namespace tuples {
class format_info { class format_info {
public: public:
@ -106,47 +106,46 @@ public:
} }
#endif // BOOST_NO_TEMPLATED_STREAMS #endif // BOOST_NO_TEMPLATED_STREAMS
}; };
} // end of namespace detail
template<class CharType> template<class CharType>
class tuple_manipulator { class tuple_manipulator {
const format_info::manipulator_type mt; const detail::format_info::manipulator_type mt;
CharType f_c; CharType f_c;
public: public:
explicit tuple_manipulator(format_info::manipulator_type m, const char c = 0) explicit tuple_manipulator(detail::format_info::manipulator_type m,
const char c = 0)
: mt(m), f_c(c) {} : mt(m), f_c(c) {}
#if defined (BOOST_NO_TEMPLATED_STREAMS) #if defined (BOOST_NO_TEMPLATED_STREAMS)
void set(std::ios &io) const { void set(std::ios &io) const {
format_info::set_manipulator(io, mt, f_c); detail::format_info::set_manipulator(io, mt, f_c);
} }
#else #else
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
template<class CharType2, class CharTrait> template<class CharType2, class CharTrait>
void set(std::basic_ios<CharType2, CharTrait> &io) const { void set(std::basic_ios<CharType2, CharTrait> &io) const {
format_info::set_manipulator(io, mt, f_c); detail::format_info::set_manipulator(io, mt, f_c);
} }
#else #else
template<class CharTrait> template<class CharTrait>
void set(std::basic_ios<CharType, CharTrait> &io) const { void set(std::basic_ios<CharType, CharTrait> &io) const {
format_info::set_manipulator(io, mt, f_c); detail::format_info::set_manipulator(io, mt, f_c);
} }
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
#endif // BOOST_NO_TEMPLATED_STREAMS #endif // BOOST_NO_TEMPLATED_STREAMS
}; };
} // end of namespace tuples
} // end of namespace detail
#if defined (BOOST_NO_TEMPLATED_STREAMS) #if defined (BOOST_NO_TEMPLATED_STREAMS)
inline std::ostream& inline std::ostream&
operator<<(std::ostream& o, const detail::tuples::tuple_manipulator<char>& m) { operator<<(std::ostream& o, const tuple_manipulator<char>& m) {
m.set(o); m.set(o);
return o; return o;
} }
inline std::istream& inline std::istream&
operator>>(std::istream& i, const detail::tuples::tuple_manipulator<char>& m) { operator>>(std::istream& i, const tuple_manipulator<char>& m) {
m.set(i); m.set(i);
return i; return i;
} }
@ -155,14 +154,14 @@ operator>>(std::istream& i, const detail::tuples::tuple_manipulator<char>& m) {
template<class CharType, class CharTrait> template<class CharType, class CharTrait>
inline std::basic_ostream<CharType, CharTrait>& inline std::basic_ostream<CharType, CharTrait>&
operator<<(std::basic_ostream<CharType, CharTrait>& o, const detail::tuples::tuple_manipulator<CharType>& m) { operator<<(std::basic_ostream<CharType, CharTrait>& o, const tuple_manipulator<CharType>& m) {
m.set(o); m.set(o);
return o; return o;
} }
template<class CharType, class CharTrait> template<class CharType, class CharTrait>
inline std::basic_istream<CharType, CharTrait>& inline std::basic_istream<CharType, CharTrait>&
operator>>(std::basic_istream<CharType, CharTrait>& i, const detail::tuples::tuple_manipulator<CharType>& m) { operator>>(std::basic_istream<CharType, CharTrait>& i, const tuple_manipulator<CharType>& m) {
m.set(i); m.set(i);
return i; return i;
} }
@ -170,18 +169,18 @@ operator>>(std::basic_istream<CharType, CharTrait>& i, const detail::tuples::tup
#endif // BOOST_NO_TEMPLATED_STREAMS #endif // BOOST_NO_TEMPLATED_STREAMS
template<class CharType> template<class CharType>
inline detail::tuples::tuple_manipulator<CharType> set_open(const CharType c) { inline tuple_manipulator<CharType> set_open(const CharType c) {
return detail::tuples::tuple_manipulator<CharType>(detail::tuples::format_info::open, c); return tuple_manipulator<CharType>(detail::format_info::open, c);
} }
template<class CharType> template<class CharType>
inline detail::tuples::tuple_manipulator<CharType> set_close(const CharType c) { inline tuple_manipulator<CharType> set_close(const CharType c) {
return detail::tuples::tuple_manipulator<CharType>(detail::tuples::format_info::close, c); return tuple_manipulator<CharType>(detail::format_info::close, c);
} }
template<class CharType> template<class CharType>
inline detail::tuples::tuple_manipulator<CharType> set_delimiter(const CharType c) { inline tuple_manipulator<CharType> set_delimiter(const CharType c) {
return detail::tuples::tuple_manipulator<CharType>(detail::tuples::format_info::delimiter, c); return tuple_manipulator<CharType>(detail::format_info::delimiter, c);
} }
@ -194,7 +193,6 @@ inline detail::tuples::tuple_manipulator<CharType> set_delimiter(const CharType
// set_open, set_close and set_delimiter // set_open, set_close and set_delimiter
namespace detail { namespace detail {
namespace tuples {
// Note: The order of the print functions is critical // Note: The order of the print functions is critical
// to let a conforming compiler find and select the correct one. // to let a conforming compiler find and select the correct one.
@ -219,7 +217,7 @@ print(std::ostream& o, const cons<T1, T2>& t) {
o << t.head; o << t.head;
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
if (tuple_length<T2>::value == 0) if (tuples::length<T2>::value == 0)
return o; return o;
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
o << d; o << d;
@ -256,7 +254,7 @@ print(std::basic_ostream<CharType, CharTrait>& o, const cons<T1, T2>& t) {
o << t.head; o << t.head;
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
if (tuple_length<T2>::value == 0) if (tuples::length<T2>::value == 0)
return o; return o;
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
o << d; o << d;
@ -266,7 +264,6 @@ print(std::basic_ostream<CharType, CharTrait>& o, const cons<T1, T2>& t) {
#endif // BOOST_NO_TEMPLATED_STREAMS #endif // BOOST_NO_TEMPLATED_STREAMS
} // namespace tuples
} // namespace detail } // namespace detail
#if defined (BOOST_NO_TEMPLATED_STREAMS) #if defined (BOOST_NO_TEMPLATED_STREAMS)
@ -275,13 +272,13 @@ inline std::ostream& operator<<(std::ostream& o, const cons<T1, T2>& t) {
if (!o.good() ) return o; if (!o.good() ) return o;
const char l = const char l =
detail::tuples::format_info::get_manipulator(o, detail::tuples::format_info::open); detail::format_info::get_manipulator(o, detail::format_info::open);
const char r = const char r =
detail::tuples::format_info::get_manipulator(o, detail::tuples::format_info::close); detail::format_info::get_manipulator(o, detail::format_info::close);
o << l; o << l;
detail::tuples::print(o, t); detail::print(o, t);
o << r; o << r;
@ -297,13 +294,13 @@ operator<<(std::basic_ostream<CharType, CharTrait>& o,
if (!o.good() ) return o; if (!o.good() ) return o;
const CharType l = const CharType l =
detail::tuples::format_info::get_manipulator(o, detail::tuples::format_info::open); detail::format_info::get_manipulator(o, detail::format_info::open);
const CharType r = const CharType r =
detail::tuples::format_info::get_manipulator(o, detail::tuples::format_info::close); detail::format_info::get_manipulator(o, detail::format_info::close);
o << l; o << l;
detail::tuples::print(o, t); detail::print(o, t);
o << r; o << r;
@ -316,7 +313,6 @@ operator<<(std::basic_ostream<CharType, CharTrait>& o,
// input stream operators // input stream operators
namespace detail { namespace detail {
namespace tuples {
#if defined (BOOST_NO_TEMPLATED_STREAMS) #if defined (BOOST_NO_TEMPLATED_STREAMS)
@ -364,7 +360,7 @@ read(std::istream &is, cons<T1, T2>& t1) {
is >> t1.head; is >> t1.head;
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
if (tuple_length<T2>::value == 0) if (tuples::length<T2>::value == 0)
return is; return is;
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
@ -373,7 +369,6 @@ read(std::istream &is, cons<T1, T2>& t1) {
return read(is, t1.tail); return read(is, t1.tail);
} }
} // end namespace tuples
} // end namespace detail } // end namespace detail
inline std::istream& inline std::istream&
@ -381,8 +376,8 @@ operator>>(std::istream &is, null_type&) {
if (!is.good() ) return is; if (!is.good() ) return is;
detail::tuples::extract_and_check_delimiter(is, detail::tuples::format_info::open); detail::extract_and_check_delimiter(is, detail::format_info::open);
detail::tuples::extract_and_check_delimiter(is, detail::tuples::format_info::close); detail::extract_and_check_delimiter(is, detail::format_info::close);
return is; return is;
} }
@ -394,11 +389,11 @@ operator>>(std::istream& is, cons<T1, T2>& t1) {
if (!is.good() ) return is; if (!is.good() ) return is;
detail::tuples::extract_and_check_delimiter(is, detail::tuples::format_info::open); detail::extract_and_check_delimiter(is, detail::format_info::open);
detail::tuples::read(is, t1); detail::read(is, t1);
detail::tuples::extract_and_check_delimiter(is, detail::tuples::format_info::close); detail::extract_and_check_delimiter(is, detail::format_info::close);
return is; return is;
} }
@ -452,7 +447,7 @@ read(std::basic_istream<CharType, CharTrait> &is, cons<T1, T2>& t1) {
is >> t1.head; is >> t1.head;
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
if (tuple_length<T2>::value == 0) if (tuples::length<T2>::value == 0)
return is; return is;
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
@ -461,7 +456,6 @@ read(std::basic_istream<CharType, CharTrait> &is, cons<T1, T2>& t1) {
return read(is, t1.tail); return read(is, t1.tail);
} }
} // end namespace tuples
} // end namespace detail } // end namespace detail
@ -471,8 +465,8 @@ operator>>(std::basic_istream<CharType, CharTrait> &is, null_type&) {
if (!is.good() ) return is; if (!is.good() ) return is;
detail::tuples::extract_and_check_delimiter(is, detail::tuples::format_info::open); detail::extract_and_check_delimiter(is, detail::format_info::open);
detail::tuples::extract_and_check_delimiter(is, detail::tuples::format_info::close); detail::extract_and_check_delimiter(is, detail::format_info::close);
return is; return is;
} }
@ -483,17 +477,18 @@ operator>>(std::basic_istream<CharType, CharTrait>& is, cons<T1, T2>& t1) {
if (!is.good() ) return is; if (!is.good() ) return is;
detail::tuples::extract_and_check_delimiter(is, detail::tuples::format_info::open); detail::extract_and_check_delimiter(is, detail::format_info::open);
detail::tuples::read(is, t1); detail::read(is, t1);
detail::tuples::extract_and_check_delimiter(is, detail::tuples::format_info::close); detail::extract_and_check_delimiter(is, detail::format_info::close);
return is; return is;
} }
#endif // BOOST_NO_TEMPLATED_STREAMS #endif // BOOST_NO_TEMPLATED_STREAMS
} // end of namespace tuples
} // end of namespace boost } // end of namespace boost
#endif // BOOST_TUPLE_IO_HPP #endif // BOOST_TUPLE_IO_HPP