Chris@16: ////////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@101: // (C) Copyright Ion Gaztanaga 2008-2013. Distributed under the Boost Chris@16: // Software License, Version 1.0. (See accompanying file Chris@16: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: // See http://www.boost.org/libs/container for documentation. Chris@16: // Chris@16: ////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: #ifndef BOOST_CONTAINER_DETAIL_VARIADIC_TEMPLATES_TOOLS_HPP Chris@16: #define BOOST_CONTAINER_DETAIL_VARIADIC_TEMPLATES_TOOLS_HPP Chris@16: Chris@101: #ifndef BOOST_CONFIG_HPP Chris@101: # include Chris@101: #endif Chris@101: Chris@101: #if defined(BOOST_HAS_PRAGMA_ONCE) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@101: #include Chris@16: #include Chris@101: Chris@16: #include Chris@16: #include //std::size_t Chris@16: Chris@16: namespace boost { Chris@16: namespace container { Chris@16: namespace container_detail { Chris@16: Chris@16: template Chris@16: class tuple; Chris@16: Chris@16: template<> class tuple<> Chris@16: {}; Chris@16: Chris@16: template Chris@16: class tuple Chris@16: : private tuple Chris@16: { Chris@16: typedef tuple inherited; Chris@16: Chris@16: public: Chris@16: tuple() { } Chris@16: Chris@16: // implicit copy-constructor is okay Chris@16: // Construct tuple from separate arguments. Chris@16: tuple(typename add_const_reference::type v, Chris@16: typename add_const_reference::type... vtail) Chris@16: : inherited(vtail...), m_head(v) Chris@16: {} Chris@16: Chris@16: // Construct tuple from another tuple. Chris@16: template Chris@16: tuple(const tuple& other) Chris@16: : m_head(other.head()), inherited(other.tail()) Chris@16: {} Chris@16: Chris@16: template Chris@16: tuple& operator=(const tuple& other) Chris@16: { Chris@16: m_head = other.head(); Chris@16: tail() = other.tail(); Chris@16: return this; Chris@16: } Chris@16: Chris@16: typename add_reference::type head() { return m_head; } Chris@16: typename add_reference::type head() const { return m_head; } Chris@16: Chris@16: inherited& tail() { return *this; } Chris@16: const inherited& tail() const { return *this; } Chris@16: Chris@16: protected: Chris@16: Head m_head; Chris@16: }; Chris@16: Chris@16: Chris@16: template Chris@16: tuple tie_forward(Values&&... values) Chris@16: { return tuple(values...); } Chris@16: Chris@16: template Chris@16: struct tuple_element; Chris@16: Chris@16: template Chris@16: struct tuple_element > Chris@16: { Chris@16: typedef typename tuple_element >::type type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct tuple_element<0, tuple > Chris@16: { Chris@16: typedef Head type; Chris@16: }; Chris@16: Chris@16: template Chris@16: class get_impl; Chris@16: Chris@16: template Chris@16: class get_impl > Chris@16: { Chris@16: typedef typename tuple_element >::type Element; Chris@16: typedef get_impl > Next; Chris@16: Chris@16: public: Chris@16: typedef typename add_reference::type type; Chris@16: typedef typename add_const_reference::type const_type; Chris@16: static type get(tuple& t) { return Next::get(t.tail()); } Chris@16: static const_type get(const tuple& t) { return Next::get(t.tail()); } Chris@16: }; Chris@16: Chris@16: template Chris@16: class get_impl<0, tuple > Chris@16: { Chris@16: public: Chris@16: typedef typename add_reference::type type; Chris@16: typedef typename add_const_reference::type const_type; Chris@16: static type get(tuple& t) { return t.head(); } Chris@16: static const_type get(const tuple& t){ return t.head(); } Chris@16: }; Chris@16: Chris@16: template Chris@16: typename get_impl >::type get(tuple& t) Chris@16: { return get_impl >::get(t); } Chris@16: Chris@16: template Chris@16: typename get_impl >::const_type get(const tuple& t) Chris@16: { return get_impl >::get(t); } Chris@16: Chris@16: //////////////////////////////////////////////////// Chris@16: // Builds an index_tuple<0, 1, 2, ..., Num-1>, that will Chris@16: // be used to "unpack" into comma-separated values Chris@16: // in a function call. Chris@16: //////////////////////////////////////////////////// Chris@16: Chris@16: template Chris@16: struct index_tuple{}; Chris@16: Chris@16: template > Chris@16: struct build_number_seq; Chris@16: Chris@16: template Chris@16: struct build_number_seq > Chris@16: : build_number_seq > Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct build_number_seq<0, index_tuple > Chris@16: { typedef index_tuple type; }; Chris@16: Chris@16: Chris@16: }}} //namespace boost { namespace container { namespace container_detail { Chris@16: Chris@16: #include Chris@16: Chris@16: #endif //#ifndef BOOST_CONTAINER_DETAIL_VARIADIC_TEMPLATES_TOOLS_HPP