From 5b40ff62c6ab31fed8e25378712208045e6c9544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20J=C3=A4rvi?= Date: Fri, 14 Sep 2001 07:55:58 +0000 Subject: [PATCH] merged tuples_subnamespace branch to main trunk [SVN r11121] --- include/boost/tuple/detail/tuple_basic.hpp | 195 +++++------ .../detail/tuple_basic_no_partial_spec.hpp | 326 +++++++++--------- include/boost/tuple/tuple.hpp | 9 + include/boost/tuple/tuple_comparison.hpp | 40 +-- include/boost/tuple/tuple_io.hpp | 85 +++-- 5 files changed, 330 insertions(+), 325 deletions(-) diff --git a/include/boost/tuple/detail/tuple_basic.hpp b/include/boost/tuple/detail/tuple_basic.hpp index 5165927..e75a294 100644 --- a/include/boost/tuple/detail/tuple_basic.hpp +++ b/include/boost/tuple/detail/tuple_basic.hpp @@ -36,15 +36,14 @@ #include "boost/type_traits/cv_traits.hpp" namespace boost { +namespace tuples { // -- null_type -------------------------------------------------------- struct null_type {}; // a helper function to provide a const null_type type temporary namespace detail { -namespace tuples { inline const null_type cnull_type() { return null_type(); } -} // end tuples } // end detail // - cons forward declaration ----------------------------------------------- @@ -60,12 +59,11 @@ template < class tuple; // tuple_length forward declaration -template struct tuple_length; +template struct length; namespace detail { -namespace tuples { // -- generate error template, referencing to non-existing members of this // template is used to produce compilation errors intentionally @@ -108,24 +106,24 @@ struct default_arg { }; // - cons getters -------------------------------------------------------- -// called: element::get(aTuple) +// called: get_class::get(aTuple) template< int N > -struct element { +struct get_class { template inline static RET get(const cons& t) { - return element::template get(t.tail); + return get_class::template get(t.tail); } template inline static RET get(cons& t) { - return element::template get(t.tail); + return get_class::template get(t.tail); } }; template<> -struct element<0> { +struct get_class<0> { template inline static RET get(const cons& t) { @@ -138,25 +136,24 @@ struct element<0> { } }; -} // end of namespace tuples } // end of namespace detail // -cons type accessors ---------------------------------------- -// typename tuple_element::type gets the type of the +// typename tuples::element::type gets the type of the // Nth element ot T, first element is at index 0 // ------------------------------------------------------- template -struct tuple_element +struct element { private: typedef typename T::tail_type Next; public: - typedef typename tuple_element::type type; + typedef typename element::type type; }; template -struct tuple_element<0,T> +struct element<0,T> { 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 // interface, so should the way to express their return types be. -template struct tuple_access_traits { +template struct access_traits { typedef const T& const_type; typedef T& non_const_type; @@ -182,7 +179,7 @@ template struct tuple_access_traits { // be non-volatile and const. 8.5.3. (5) }; -template struct tuple_access_traits { +template struct access_traits { typedef T& const_type; typedef T& non_const_type; @@ -194,14 +191,14 @@ template struct tuple_access_traits { // get function for non-const cons-lists, returns a reference to the element template -inline typename tuple_access_traits< - typename tuple_element >::type +inline typename access_traits< + typename element >::type >::non_const_type get(cons& c) { - return detail::tuples::element::template + return detail::get_class::template get< - typename tuple_access_traits< - typename tuple_element >::type + typename access_traits< + typename element >::type >::non_const_type>(c); } @@ -209,14 +206,14 @@ get(cons& c) { // the element. If the element is a reference, returns the reference // as such (that is, can return a non-const reference) template -inline typename tuple_access_traits< - typename tuple_element >::type +inline typename access_traits< + typename element >::type >::const_type get(const cons& c) { - return detail::tuples::element::template + return detail::get_class::template get< - typename tuple_access_traits< - typename tuple_element >::type + typename access_traits< + typename element >::type >::const_type>(c); } @@ -234,25 +231,25 @@ struct cons { head_type head; tail_type tail; - typename tuple_access_traits::non_const_type + typename access_traits::non_const_type get_head() { return head; } - typename tuple_access_traits::non_const_type + typename access_traits::non_const_type get_tail() { return tail; } - typename tuple_access_traits::const_type + typename access_traits::const_type get_head() const { return head; } - typename tuple_access_traits::const_type + typename access_traits::const_type get_tail() const { return tail; } - cons() : head(detail::tuples::default_arg::f()), tail() {} + cons() : head(detail::default_arg::f()), tail() {} // the argument for head is not strictly needed, but it prevents // array type elements. This is good, since array type elements // cannot be supported properly in any case (no assignment, // copy works only if the tails are exactly the same type, ...) - cons(typename tuple_access_traits::parameter_type h, + cons(typename access_traits::parameter_type h, const tail_type& t) : head (h), tail(t) {} @@ -261,7 +258,7 @@ struct cons { cons( T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7, T8& t8, T9& t9, T10& t10 ) : 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 @@ -280,22 +277,22 @@ struct cons { template cons& operator=( const std::pair& u ) { - BOOST_STATIC_ASSERT(tuple_length::value == 2); // check length = 2 + BOOST_STATIC_ASSERT(length::value == 2); // check length = 2 head = u.first; tail.head = u.second; return *this; } // get member functions (non-const and const) template - typename tuple_access_traits< - typename tuple_element >::type + typename access_traits< + typename element >::type >::non_const_type get() { return boost::get(*this); // delegate to non-member get } template - typename tuple_access_traits< - typename tuple_element >::type + typename access_traits< + typename element >::type >::const_type get() const { return boost::get(*this); // delegate to non-member get @@ -310,19 +307,19 @@ struct cons { head_type head; - typename tuple_access_traits::non_const_type + typename access_traits::non_const_type get_head() { return head; } null_type get_tail() { return null_type(); } - typename tuple_access_traits::const_type + typename access_traits::const_type get_head() const { return head; } const null_type get_tail() const { return null_type(); } - cons() : head(detail::tuples::default_arg::f()) {} + cons() : head(detail::default_arg::f()) {} - cons(typename tuple_access_traits::parameter_type h, + cons(typename access_traits::parameter_type h, const null_type& = null_type()) : head (h) {} @@ -344,16 +341,16 @@ struct cons { cons& operator=(const cons& u) { head = u.head; return *this; } template - typename tuple_access_traits< - typename tuple_element::type + typename access_traits< + typename element::type >::non_const_type get() { return boost::get(*this); } template - typename tuple_access_traits< - typename tuple_element::type + typename access_traits< + typename element::type >::const_type get() const { return boost::get(*this); @@ -364,18 +361,17 @@ struct cons { // templates for finding out the length of the tuple ------------------- template -struct tuple_length { - BOOST_STATIC_CONSTANT(int, value = 1 + tuple_length::value); +struct length { + BOOST_STATIC_CONSTANT(int, value = 1 + length::value); }; template<> -struct tuple_length { +struct length { BOOST_STATIC_CONSTANT(int, value = 0); }; namespace detail { -namespace tuples { // Tuple to cons mapper -------------------------------------------------- template class tuple : - public detail::tuples::map_tuple_to_cons::type + public detail::map_tuple_to_cons::type { public: typedef typename - detail::tuples::map_tuple_to_cons::type inherited; + detail::map_tuple_to_cons::type inherited; typedef typename inherited::head_type head_type; typedef typename inherited::tail_type tail_type; -// tuple_access_traits::parameter_type takes non-reference types as const T& +// access_traits::parameter_type takes non-reference types as const T& explicit tuple( - typename tuple_access_traits::parameter_type t0 - = detail::tuples::default_arg::f(), - typename tuple_access_traits::parameter_type t1 - = detail::tuples::default_arg::f(), - typename tuple_access_traits::parameter_type t2 - = detail::tuples::default_arg::f(), - typename tuple_access_traits::parameter_type t3 - = detail::tuples::default_arg::f(), - typename tuple_access_traits::parameter_type t4 - = detail::tuples::default_arg::f(), - typename tuple_access_traits::parameter_type t5 - = detail::tuples::default_arg::f(), - typename tuple_access_traits::parameter_type t6 - = detail::tuples::default_arg::f(), - typename tuple_access_traits::parameter_type t7 - = detail::tuples::default_arg::f(), - typename tuple_access_traits::parameter_type t8 - = detail::tuples::default_arg::f(), - typename tuple_access_traits::parameter_type t9 - = detail::tuples::default_arg::f()) + typename access_traits::parameter_type t0 + = detail::default_arg::f(), + typename access_traits::parameter_type t1 + = detail::default_arg::f(), + typename access_traits::parameter_type t2 + = detail::default_arg::f(), + typename access_traits::parameter_type t3 + = detail::default_arg::f(), + typename access_traits::parameter_type t4 + = detail::default_arg::f(), + typename access_traits::parameter_type t5 + = detail::default_arg::f(), + typename access_traits::parameter_type t6 + = detail::default_arg::f(), + typename access_traits::parameter_type t7 + = detail::default_arg::f(), + typename access_traits::parameter_type t8 + = detail::default_arg::f(), + typename access_traits::parameter_type t9 + = detail::default_arg::f()) : inherited(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) {} @@ -449,7 +444,7 @@ public: template tuple& operator=(const std::pair& k) { - BOOST_STATIC_ASSERT(tuple_length::value == 2);// check_length = 2 + BOOST_STATIC_ASSERT(length::value == 2);// check_length = 2 this->head = k.first; this->tail.head = k.second; return *this; @@ -469,7 +464,6 @@ public: // Swallows any assignment (by Doug Gregor) namespace detail { -namespace tuples { struct swallow_assign { @@ -478,12 +472,12 @@ struct swallow_assign { return *this; } }; -} // namespace tuples + } // namespace detail // "ignore" allows tuple positions to be ignored when using "tie". namespace { - detail::tuples::swallow_assign ignore; + detail::swallow_assign ignore; } // --------------------------------------------------------------------------- @@ -530,7 +524,7 @@ struct make_tuple_traits { template struct make_tuple_traits { typedef typename - detail::tuples::generate_error:: + detail::generate_error:: do_not_use_with_reference_type error; }; @@ -570,7 +564,6 @@ struct make_tuple_traits >{ namespace detail { -namespace tuples { // a helper traits to make the make_tuple functions shorter (Vesa Karvonen's // suggestion) @@ -594,7 +587,6 @@ struct make_tuple_mapper { typename make_tuple_traits::type> type; }; -} // end tuples } // end detail // -make_tuple function templates ----------------------------------- @@ -603,85 +595,85 @@ inline tuple<> make_tuple() { } template -inline typename boost::detail::tuples::make_tuple_mapper::type +inline typename detail::make_tuple_mapper::type make_tuple(const T0& t0) { - return typename boost::detail::tuples::make_tuple_mapper::type(t0); + return typename detail::make_tuple_mapper::type(t0); } template -inline typename boost::detail::tuples::make_tuple_mapper::type +inline typename detail::make_tuple_mapper::type make_tuple(const T0& t0, const T1& t1) { - return typename boost::detail::tuples::make_tuple_mapper::type(t0, t1); + return typename detail::make_tuple_mapper::type(t0, t1); } template -inline typename boost::detail::tuples::make_tuple_mapper::type +inline typename detail::make_tuple_mapper::type make_tuple(const T0& t0, const T1& t1, const T2& t2) { - return typename boost::detail::tuples::make_tuple_mapper::type(t0, t1, t2); + return typename detail::make_tuple_mapper::type(t0, t1, t2); } template -inline typename boost::detail::tuples::make_tuple_mapper::type +inline typename detail::make_tuple_mapper::type make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3) { - return typename boost::detail::tuples::make_tuple_mapper::type + return typename detail::make_tuple_mapper::type (t0, t1, t2, t3); } template -inline typename boost::detail::tuples::make_tuple_mapper::type +inline typename detail::make_tuple_mapper::type make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, const T4& t4) { - return typename boost::detail::tuples::make_tuple_mapper::type + return typename detail::make_tuple_mapper::type (t0, t1, t2, t3, t4); } template -inline typename boost::detail::tuples::make_tuple_mapper::type +inline typename detail::make_tuple_mapper::type make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5) { - return typename boost::detail::tuples::make_tuple_mapper::type + return typename detail::make_tuple_mapper::type (t0, t1, t2, t3, t4, t5); } template -inline typename boost::detail::tuples::make_tuple_mapper::type +inline typename detail::make_tuple_mapper::type make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6) { - return typename boost::detail::tuples::make_tuple_mapper + return typename detail::make_tuple_mapper ::type (t0, t1, t2, t3, t4, t5, t6); } template -inline typename boost::detail::tuples::make_tuple_mapper::type +inline typename detail::make_tuple_mapper::type 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) { - return typename boost::detail::tuples::make_tuple_mapper + return typename detail::make_tuple_mapper ::type (t0, t1, t2, t3, t4, t5, t6, t7); } template -inline typename boost::detail::tuples::make_tuple_mapper +inline typename detail::make_tuple_mapper ::type 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 T8& t8) { - return typename boost::detail::tuples::make_tuple_mapper + return typename detail::make_tuple_mapper ::type (t0, t1, t2, t3, t4, t5, t6, t7, t8); } template -inline typename boost::detail::tuples::make_tuple_mapper +inline typename detail::make_tuple_mapper ::type 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 T8& t8, const T9& t9) { - return typename boost::detail::tuples::make_tuple_mapper + return typename detail::make_tuple_mapper ::type (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); } +} // end of namespace tuples } // end of namespace boost diff --git a/include/boost/tuple/detail/tuple_basic_no_partial_spec.hpp b/include/boost/tuple/detail/tuple_basic_no_partial_spec.hpp index 0fc0564..f98ed61 100644 --- a/include/boost/tuple/detail/tuple_basic_no_partial_spec.hpp +++ b/include/boost/tuple/detail/tuple_basic_no_partial_spec.hpp @@ -41,6 +41,7 @@ #endif namespace boost { +namespace tuples { // null_type denotes the end of a list built with "cons" struct null_type @@ -53,7 +54,7 @@ namespace boost { inline const null_type cnull_type() { return null_type(); } namespace detail { - namespace tuples { + // Takes a pointer and routes all assignments to whatever it points to template struct assign_to_pointee @@ -82,7 +83,6 @@ namespace boost { } }; - } // end of namespace tuples } // end of namespace detail // cons builds a heterogenous list of types @@ -103,9 +103,9 @@ namespace boost { typename boost::add_reference::type get_tail() const { return tail; } #if defined BOOST_MSVC - template + template 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 template - explicit cons(const head_type& h = head_type(), - const T& t) : head(h), tail(t.head, t.tail) + explicit cons(const head_type& h, const T& t) : + head(h), tail(t.head, t.tail) { } @@ -139,7 +139,7 @@ namespace boost { }; namespace detail { - namespace tuples { + // Determines if the parameter is null_type template struct is_null_type { enum { RET = 0 }; }; template<> struct is_null_type { enum { RET = 1 }; }; @@ -176,16 +176,16 @@ namespace boost { > struct map_tuple_to_cons { - typedef typename detail::tuples::build_cons::RET cons10; - typedef typename detail::tuples::build_cons::RET cons9; - typedef typename detail::tuples::build_cons::RET cons8; - typedef typename detail::tuples::build_cons::RET cons7; - typedef typename detail::tuples::build_cons::RET cons6; - typedef typename detail::tuples::build_cons::RET cons5; - typedef typename detail::tuples::build_cons::RET cons4; - typedef typename detail::tuples::build_cons::RET cons3; - typedef typename detail::tuples::build_cons::RET cons2; - typedef typename detail::tuples::build_cons::RET cons1; + typedef typename detail::build_cons::RET cons10; + typedef typename detail::build_cons::RET cons9; + typedef typename detail::build_cons::RET cons8; + typedef typename detail::build_cons::RET cons7; + typedef typename detail::build_cons::RET cons6; + typedef typename detail::build_cons::RET cons5; + typedef typename detail::build_cons::RET cons4; + typedef typename detail::build_cons::RET cons3; + typedef typename detail::build_cons::RET cons2; + typedef typename detail::build_cons::RET cons1; }; // Workaround the lack of partial specialization in some compilers @@ -213,15 +213,16 @@ namespace boost { typedef typename Tuple::head_type RET; }; }; - } // detail - } // tuples + + } // namespace detail + // Return the Nth type of the given Tuple template - struct tuple_element + struct element { private: - typedef detail::tuples::_element_type nth_type; + typedef detail::_element_type nth_type; public: typedef typename nth_type::template inner::RET RET; @@ -229,13 +230,13 @@ namespace boost { }; namespace detail { - namespace tuples { + // Return a reference to the Nth type of the given Tuple template - struct tuple_element_ref + struct element_ref { private: - typedef typename tuple_element::RET elt_type; + typedef typename element::RET elt_type; public: typedef typename add_reference::type RET; @@ -244,53 +245,56 @@ namespace boost { // Return a const reference to the Nth type of the given Tuple template - struct tuple_element_const_ref + struct element_const_ref { private: - typedef typename tuple_element::RET elt_type; + typedef typename element::RET elt_type; public: typedef typename add_reference::type RET; typedef RET type; }; - } - } + + } // namespace detail + // Get length of this tuple template - struct tuple_length + struct length { - enum { value = 1 + tuple_length::value }; + BOOST_STATIC_CONSTANT(int, value = 1 + length::value); }; template<> - struct tuple_length + struct length { - enum { value = 0 }; + BOOST_STATIC_CONSTANT(int, value = 0); }; + namespace detail { + // Reference the Nth element in a tuple and retrieve it with "get" template - struct element + struct get_class { template static inline - typename detail::tuples::tuple_element_ref >::RET + typename detail::element_ref >::RET get(cons& t) { - return element::get(t.tail); + return get_class::get(t.tail); } template static inline - typename detail::tuples::tuple_element_const_ref >::RET + typename detail::element_const_ref >::RET get(const cons& t) { - return element::get(t.tail); + return get_class::get(t.tail); } }; template<> - struct element<0> + struct get_class<0> { template static inline @@ -309,6 +313,8 @@ namespace boost { } }; + } // namespace detail + // tuple class template< typename T1, @@ -323,10 +329,10 @@ namespace boost { typename T10 = null_type > class tuple : - public detail::tuples::map_tuple_to_cons::cons1 + public detail::map_tuple_to_cons::cons1 { private: - typedef detail::tuples::map_tuple_to_cons mapped_tuple; + typedef detail::map_tuple_to_cons mapped_tuple; typedef typename mapped_tuple::cons10 cons10; typedef typename mapped_tuple::cons9 cons9; typedef typename mapped_tuple::cons8 cons8; @@ -380,22 +386,23 @@ namespace boost { }; namespace detail { - namespace tuples { + template struct workaround_holder {}; - }} + + } // namespace detail template - typename detail::tuples::tuple_element_ref >::RET - get(cons& t, detail::tuples::workaround_holder* = 0) + typename detail::element_ref >::RET + get(cons& t, detail::workaround_holder* = 0) { - return element::get(t); + return detail::get_class::get(t); } template - typename detail::tuples::tuple_element_const_ref >::RET - get(const cons& t, detail::tuples::workaround_holder* = 0) + typename detail::element_const_ref >::RET + get(const cons& t, detail::workaround_holder* = 0) { - return element::get(t); + return detail::get_class::get(t); } // Make a tuple @@ -491,185 +498,186 @@ namespace boost { // Tie variables into a tuple template inline - tuple > + tuple > tie(T1& t1) { - return make_tuple(detail::tuples::assign_to_pointee(&t1)); + return make_tuple(detail::assign_to_pointee(&t1)); } // Tie variables into a tuple template inline - tuple, - detail::tuples::assign_to_pointee > + tuple, + detail::assign_to_pointee > tie(T1& t1, T2& t2) { - return make_tuple(detail::tuples::assign_to_pointee(&t1), - detail::tuples::assign_to_pointee(&t2)); + return make_tuple(detail::assign_to_pointee(&t1), + detail::assign_to_pointee(&t2)); } // Tie variables into a tuple template inline - tuple, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee > + tuple, + detail::assign_to_pointee, + detail::assign_to_pointee > tie(T1& t1, T2& t2, T3& t3) { - return make_tuple(detail::tuples::assign_to_pointee(&t1), - detail::tuples::assign_to_pointee(&t2), - detail::tuples::assign_to_pointee(&t3)); + return make_tuple(detail::assign_to_pointee(&t1), + detail::assign_to_pointee(&t2), + detail::assign_to_pointee(&t3)); } // Tie variables into a tuple template inline - tuple, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee > + tuple, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee > tie(T1& t1, T2& t2, T3& t3, T4& t4) { - return make_tuple(detail::tuples::assign_to_pointee(&t1), - detail::tuples::assign_to_pointee(&t2), - detail::tuples::assign_to_pointee(&t3), - detail::tuples::assign_to_pointee(&t4)); + return make_tuple(detail::assign_to_pointee(&t1), + detail::assign_to_pointee(&t2), + detail::assign_to_pointee(&t3), + detail::assign_to_pointee(&t4)); } // Tie variables into a tuple template inline - tuple, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee > + tuple, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee > tie(T1& t1, T2& t2, T3& t3, T4& t4, T5 &t5) { - return make_tuple(detail::tuples::assign_to_pointee(&t1), - detail::tuples::assign_to_pointee(&t2), - detail::tuples::assign_to_pointee(&t3), - detail::tuples::assign_to_pointee(&t4), - detail::tuples::assign_to_pointee(&t5)); + return make_tuple(detail::assign_to_pointee(&t1), + detail::assign_to_pointee(&t2), + detail::assign_to_pointee(&t3), + detail::assign_to_pointee(&t4), + detail::assign_to_pointee(&t5)); } // Tie variables into a tuple template inline - tuple, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee > + tuple, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee > tie(T1& t1, T2& t2, T3& t3, T4& t4, T5 &t5, T6 &t6) { - return make_tuple(detail::tuples::assign_to_pointee(&t1), - detail::tuples::assign_to_pointee(&t2), - detail::tuples::assign_to_pointee(&t3), - detail::tuples::assign_to_pointee(&t4), - detail::tuples::assign_to_pointee(&t5), - detail::tuples::assign_to_pointee(&t6)); + return make_tuple(detail::assign_to_pointee(&t1), + detail::assign_to_pointee(&t2), + detail::assign_to_pointee(&t3), + detail::assign_to_pointee(&t4), + detail::assign_to_pointee(&t5), + detail::assign_to_pointee(&t6)); } // Tie variables into a tuple template inline - tuple, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee > + tuple, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee > tie(T1& t1, T2& t2, T3& t3, T4& t4, T5 &t5, T6 &t6, T7 &t7) { - return make_tuple(detail::tuples::assign_to_pointee(&t1), - detail::tuples::assign_to_pointee(&t2), - detail::tuples::assign_to_pointee(&t3), - detail::tuples::assign_to_pointee(&t4), - detail::tuples::assign_to_pointee(&t5), - detail::tuples::assign_to_pointee(&t6), - detail::tuples::assign_to_pointee(&t7)); + return make_tuple(detail::assign_to_pointee(&t1), + detail::assign_to_pointee(&t2), + detail::assign_to_pointee(&t3), + detail::assign_to_pointee(&t4), + detail::assign_to_pointee(&t5), + detail::assign_to_pointee(&t6), + detail::assign_to_pointee(&t7)); } // Tie variables into a tuple template inline - tuple, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee > + tuple, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee > 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), - detail::tuples::assign_to_pointee(&t2), - detail::tuples::assign_to_pointee(&t3), - detail::tuples::assign_to_pointee(&t4), - detail::tuples::assign_to_pointee(&t5), - detail::tuples::assign_to_pointee(&t6), - detail::tuples::assign_to_pointee(&t7), - detail::tuples::assign_to_pointee(&t8)); + return make_tuple(detail::assign_to_pointee(&t1), + detail::assign_to_pointee(&t2), + detail::assign_to_pointee(&t3), + detail::assign_to_pointee(&t4), + detail::assign_to_pointee(&t5), + detail::assign_to_pointee(&t6), + detail::assign_to_pointee(&t7), + detail::assign_to_pointee(&t8)); } // Tie variables into a tuple template inline - tuple, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee > + tuple, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee > 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), - detail::tuples::assign_to_pointee(&t2), - detail::tuples::assign_to_pointee(&t3), - detail::tuples::assign_to_pointee(&t4), - detail::tuples::assign_to_pointee(&t5), - detail::tuples::assign_to_pointee(&t6), - detail::tuples::assign_to_pointee(&t7), - detail::tuples::assign_to_pointee(&t8), - detail::tuples::assign_to_pointee(&t9)); + return make_tuple(detail::assign_to_pointee(&t1), + detail::assign_to_pointee(&t2), + detail::assign_to_pointee(&t3), + detail::assign_to_pointee(&t4), + detail::assign_to_pointee(&t5), + detail::assign_to_pointee(&t6), + detail::assign_to_pointee(&t7), + detail::assign_to_pointee(&t8), + detail::assign_to_pointee(&t9)); } // Tie variables into a tuple template inline - tuple, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee, - detail::tuples::assign_to_pointee > + tuple, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee, + detail::assign_to_pointee > 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), - detail::tuples::assign_to_pointee(&t2), - detail::tuples::assign_to_pointee(&t3), - detail::tuples::assign_to_pointee(&t4), - detail::tuples::assign_to_pointee(&t5), - detail::tuples::assign_to_pointee(&t6), - detail::tuples::assign_to_pointee(&t7), - detail::tuples::assign_to_pointee(&t8), - detail::tuples::assign_to_pointee(&t9), - detail::tuples::assign_to_pointee(&t10)); + return make_tuple(detail::assign_to_pointee(&t1), + detail::assign_to_pointee(&t2), + detail::assign_to_pointee(&t3), + detail::assign_to_pointee(&t4), + detail::assign_to_pointee(&t5), + detail::assign_to_pointee(&t6), + detail::assign_to_pointee(&t7), + detail::assign_to_pointee(&t8), + detail::assign_to_pointee(&t9), + detail::assign_to_pointee(&t10)); } // "ignore" allows tuple positions to be ignored when using "tie". namespace { - detail::tuples::swallow_assign ignore; + detail::swallow_assign ignore; } +} // namespace tuples } // namespace boost #endif // BOOST_TUPLE_BASIC_NO_PARTIAL_SPEC_HPP diff --git a/include/boost/tuple/tuple.hpp b/include/boost/tuple/tuple.hpp index bd39730..8b8f6e6 100644 --- a/include/boost/tuple/tuple.hpp +++ b/include/boost/tuple/tuple.hpp @@ -32,5 +32,14 @@ #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 diff --git a/include/boost/tuple/tuple_comparison.hpp b/include/boost/tuple/tuple_comparison.hpp index a34d67d..cf3d2c9 100644 --- a/include/boost/tuple/tuple_comparison.hpp +++ b/include/boost/tuple/tuple_comparison.hpp @@ -38,6 +38,7 @@ 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; } @@ -48,7 +49,6 @@ inline bool operator>(const null_type&, const null_type&) { return false; } namespace detail { -namespace tuples { // comparison operators check statically the length of its operands and // delegate the comparing task to the following functions. Hence // 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<> inline bool gte(const null_type&, const null_type&) { return true; } -} // end of namespace tuples } // end of namespace detail @@ -116,10 +115,10 @@ inline bool gte(const null_type&, const null_type&) { retur template inline bool operator==(const cons& lhs, const cons& rhs) { - // check that tuple_lengths are equal - BOOST_STATIC_ASSERT(tuple_length::value == tuple_length::value); + // check that tuple lengths are equal + BOOST_STATIC_ASSERT(length::value == length::value); - return detail::tuples::eq(lhs, rhs); + return detail::eq(lhs, rhs); } // not equal ----- @@ -128,52 +127,53 @@ template inline bool operator!=(const cons& lhs, const cons& rhs) { - // check that tuple_lengths are equal - BOOST_STATIC_ASSERT(tuple_length::value == tuple_length::value); + // check that tuple lengths are equal + BOOST_STATIC_ASSERT(length::value == length::value); - return detail::tuples::neq(lhs, rhs); + return detail::neq(lhs, rhs); } // < template inline bool operator<(const cons& lhs, const cons& rhs) { - // check that tuple_lengths are equal - BOOST_STATIC_ASSERT(tuple_length::value == tuple_length::value); + // check that tuple lengths are equal + BOOST_STATIC_ASSERT(length::value == length::value); - return detail::tuples::lt(lhs, rhs); + return detail::lt(lhs, rhs); } // > template inline bool operator>(const cons& lhs, const cons& rhs) { - // check that tuple_lengths are equal - BOOST_STATIC_ASSERT(tuple_length::value == tuple_length::value); + // check that tuple lengths are equal + BOOST_STATIC_ASSERT(length::value == length::value); - return detail::tuples::gt(lhs, rhs); + return detail::gt(lhs, rhs); } // <= template inline bool operator<=(const cons& lhs, const cons& rhs) { - // check that tuple_lengths are equal - BOOST_STATIC_ASSERT(tuple_length::value == tuple_length::value); + // check that tuple lengths are equal + BOOST_STATIC_ASSERT(length::value == length::value); - return detail::tuples::lte(lhs, rhs); + return detail::lte(lhs, rhs); } // >= template inline bool operator>=(const cons& lhs, const cons& rhs) { - // check that tuple_lengths are equal - BOOST_STATIC_ASSERT(tuple_length::value == tuple_length::value); + // check that tuple lengths are equal + BOOST_STATIC_ASSERT(length::value == length::value); - return detail::tuples::gte(lhs, rhs); + return detail::gte(lhs, rhs); } +} // end of namespace tuples } // end of namespace boost diff --git a/include/boost/tuple/tuple_io.hpp b/include/boost/tuple/tuple_io.hpp index 3e8896f..64514f0 100644 --- a/include/boost/tuple/tuple_io.hpp +++ b/include/boost/tuple/tuple_io.hpp @@ -39,9 +39,9 @@ namespace boost { +namespace tuples { namespace detail { -namespace tuples { class format_info { public: @@ -106,47 +106,46 @@ public: } #endif // BOOST_NO_TEMPLATED_STREAMS }; + +} // end of namespace detail template class tuple_manipulator { - const format_info::manipulator_type mt; + const detail::format_info::manipulator_type mt; CharType f_c; 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) {} #if defined (BOOST_NO_TEMPLATED_STREAMS) void set(std::ios &io) const { - format_info::set_manipulator(io, mt, f_c); + detail::format_info::set_manipulator(io, mt, f_c); } #else #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) template void set(std::basic_ios &io) const { - format_info::set_manipulator(io, mt, f_c); + detail::format_info::set_manipulator(io, mt, f_c); } #else template void set(std::basic_ios &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_TEMPLATED_STREAMS }; -} // end of namespace tuples -} // end of namespace detail - - #if defined (BOOST_NO_TEMPLATED_STREAMS) inline std::ostream& -operator<<(std::ostream& o, const detail::tuples::tuple_manipulator& m) { +operator<<(std::ostream& o, const tuple_manipulator& m) { m.set(o); return o; } inline std::istream& -operator>>(std::istream& i, const detail::tuples::tuple_manipulator& m) { +operator>>(std::istream& i, const tuple_manipulator& m) { m.set(i); return i; } @@ -155,14 +154,14 @@ operator>>(std::istream& i, const detail::tuples::tuple_manipulator& m) { template inline std::basic_ostream& -operator<<(std::basic_ostream& o, const detail::tuples::tuple_manipulator& m) { +operator<<(std::basic_ostream& o, const tuple_manipulator& m) { m.set(o); return o; } template inline std::basic_istream& -operator>>(std::basic_istream& i, const detail::tuples::tuple_manipulator& m) { +operator>>(std::basic_istream& i, const tuple_manipulator& m) { m.set(i); return i; } @@ -170,18 +169,18 @@ operator>>(std::basic_istream& i, const detail::tuples::tup #endif // BOOST_NO_TEMPLATED_STREAMS template -inline detail::tuples::tuple_manipulator set_open(const CharType c) { - return detail::tuples::tuple_manipulator(detail::tuples::format_info::open, c); +inline tuple_manipulator set_open(const CharType c) { + return tuple_manipulator(detail::format_info::open, c); } template -inline detail::tuples::tuple_manipulator set_close(const CharType c) { - return detail::tuples::tuple_manipulator(detail::tuples::format_info::close, c); +inline tuple_manipulator set_close(const CharType c) { + return tuple_manipulator(detail::format_info::close, c); } template -inline detail::tuples::tuple_manipulator set_delimiter(const CharType c) { - return detail::tuples::tuple_manipulator(detail::tuples::format_info::delimiter, c); +inline tuple_manipulator set_delimiter(const CharType c) { + return tuple_manipulator(detail::format_info::delimiter, c); } @@ -194,7 +193,6 @@ inline detail::tuples::tuple_manipulator set_delimiter(const CharType // set_open, set_close and set_delimiter namespace detail { -namespace tuples { // Note: The order of the print functions is critical // to let a conforming compiler find and select the correct one. @@ -219,7 +217,7 @@ print(std::ostream& o, const cons& t) { o << t.head; #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) - if (tuple_length::value == 0) + if (tuples::length::value == 0) return o; #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION o << d; @@ -256,7 +254,7 @@ print(std::basic_ostream& o, const cons& t) { o << t.head; #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) - if (tuple_length::value == 0) + if (tuples::length::value == 0) return o; #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION o << d; @@ -266,7 +264,6 @@ print(std::basic_ostream& o, const cons& t) { #endif // BOOST_NO_TEMPLATED_STREAMS -} // namespace tuples } // namespace detail #if defined (BOOST_NO_TEMPLATED_STREAMS) @@ -275,13 +272,13 @@ inline std::ostream& operator<<(std::ostream& o, const cons& t) { if (!o.good() ) return o; 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 = - detail::tuples::format_info::get_manipulator(o, detail::tuples::format_info::close); + detail::format_info::get_manipulator(o, detail::format_info::close); o << l; - detail::tuples::print(o, t); + detail::print(o, t); o << r; @@ -297,13 +294,13 @@ operator<<(std::basic_ostream& o, if (!o.good() ) return o; 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 = - detail::tuples::format_info::get_manipulator(o, detail::tuples::format_info::close); + detail::format_info::get_manipulator(o, detail::format_info::close); o << l; - detail::tuples::print(o, t); + detail::print(o, t); o << r; @@ -316,7 +313,6 @@ operator<<(std::basic_ostream& o, // input stream operators namespace detail { -namespace tuples { #if defined (BOOST_NO_TEMPLATED_STREAMS) @@ -364,7 +360,7 @@ read(std::istream &is, cons& t1) { is >> t1.head; #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) - if (tuple_length::value == 0) + if (tuples::length::value == 0) return is; #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION @@ -373,7 +369,6 @@ read(std::istream &is, cons& t1) { return read(is, t1.tail); } -} // end namespace tuples } // end namespace detail inline std::istream& @@ -381,8 +376,8 @@ operator>>(std::istream &is, null_type&) { if (!is.good() ) return is; - detail::tuples::extract_and_check_delimiter(is, detail::tuples::format_info::open); - detail::tuples::extract_and_check_delimiter(is, detail::tuples::format_info::close); + detail::extract_and_check_delimiter(is, detail::format_info::open); + detail::extract_and_check_delimiter(is, detail::format_info::close); return is; } @@ -394,11 +389,11 @@ operator>>(std::istream& is, cons& t1) { 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; } @@ -452,7 +447,7 @@ read(std::basic_istream &is, cons& t1) { is >> t1.head; #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) - if (tuple_length::value == 0) + if (tuples::length::value == 0) return is; #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION @@ -461,7 +456,6 @@ read(std::basic_istream &is, cons& t1) { return read(is, t1.tail); } -} // end namespace tuples } // end namespace detail @@ -471,8 +465,8 @@ operator>>(std::basic_istream &is, null_type&) { if (!is.good() ) return is; - detail::tuples::extract_and_check_delimiter(is, detail::tuples::format_info::open); - detail::tuples::extract_and_check_delimiter(is, detail::tuples::format_info::close); + detail::extract_and_check_delimiter(is, detail::format_info::open); + detail::extract_and_check_delimiter(is, detail::format_info::close); return is; } @@ -483,17 +477,18 @@ operator>>(std::basic_istream& is, cons& t1) { 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; } #endif // BOOST_NO_TEMPLATED_STREAMS +} // end of namespace tuples } // end of namespace boost #endif // BOOST_TUPLE_IO_HPP