Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:34:56

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2008-2013. Distributed under the Boost
0004 // Software License, Version 1.0. (See accompanying file
0005 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // See http://www.boost.org/libs/container for documentation.
0008 //
0009 //////////////////////////////////////////////////////////////////////////////
0010 
0011 #ifndef BOOST_CONTAINER_DETAIL_VARIADIC_TEMPLATES_TOOLS_HPP
0012 #define BOOST_CONTAINER_DETAIL_VARIADIC_TEMPLATES_TOOLS_HPP
0013 
0014 #ifndef BOOST_CONFIG_HPP
0015 #  include <boost/config.hpp>
0016 #endif
0017 
0018 #if defined(BOOST_HAS_PRAGMA_ONCE)
0019 #  pragma once
0020 #endif
0021 
0022 #include <boost/container/detail/config_begin.hpp>
0023 #include <boost/container/detail/workaround.hpp>
0024 #include <boost/move/utility_core.hpp>
0025 
0026 #include <boost/container/detail/type_traits.hpp>
0027 #include <cstddef>   //std::size_t
0028 
0029 namespace boost {
0030 namespace container {
0031 namespace dtl {
0032 
0033 template<typename... Values>
0034 class tuple;
0035 
0036 template<> class tuple<>
0037 {};
0038 
0039 template<typename Head, typename... Tail>
0040 class tuple<Head, Tail...>
0041    : private tuple<Tail...>
0042 {
0043    typedef tuple<Tail...> inherited;
0044 
0045    public:
0046    tuple()
0047       : inherited(), m_head()
0048    {}
0049 
0050    template<class U, class ...Args>
0051    tuple(U &&u, Args && ...args)
0052       : inherited(::boost::forward<Args>(args)...), m_head(::boost::forward<U>(u))
0053    {}
0054 
0055    // Construct tuple from another tuple.
0056    template<typename... VValues>
0057    tuple(const tuple<VValues...>& other)
0058       : inherited(other.tail()), m_head(other.head())
0059    {}
0060 
0061    template<typename... VValues>
0062    tuple& operator=(const tuple<VValues...>& other)
0063    {
0064       m_head = other.head();
0065       tail() = other.tail();
0066       return this;
0067    }
0068 
0069    typename add_reference<Head>::type head()             {  return m_head; }
0070    typename add_reference<const Head>::type head() const {  return m_head; }
0071 
0072    inherited& tail()             { return *this; }
0073    const inherited& tail() const { return *this; }
0074 
0075    protected:
0076    Head m_head;
0077 };
0078 
0079 
0080 template<typename... Values>
0081 tuple<Values&&...> forward_as_tuple_impl(Values&&... values)
0082 { return tuple<Values&&...>(::boost::forward<Values>(values)...); }
0083 
0084 template<int I, typename Tuple>
0085 struct tuple_element;
0086 
0087 template<int I, typename Head, typename... Tail>
0088 struct tuple_element<I, tuple<Head, Tail...> >
0089 {
0090    typedef typename tuple_element<I-1, tuple<Tail...> >::type type;
0091 };
0092 
0093 template<typename Head, typename... Tail>
0094 struct tuple_element<0, tuple<Head, Tail...> >
0095 {
0096    typedef Head type;
0097 };
0098 
0099 template<int I, typename Tuple>
0100 class get_impl;
0101 
0102 template<int I, typename Head, typename... Values>
0103 class get_impl<I, tuple<Head, Values...> >
0104 {
0105    typedef typename tuple_element<I-1, tuple<Values...> >::type   Element;
0106    typedef get_impl<I-1, tuple<Values...> >                       Next;
0107 
0108    public:
0109    typedef typename add_reference<Element>::type                  type;
0110    typedef typename add_const_reference<Element>::type            const_type;
0111    static type get(tuple<Head, Values...>& t)              { return Next::get(t.tail()); }
0112    static const_type get(const tuple<Head, Values...>& t)  { return Next::get(t.tail()); }
0113 };
0114 
0115 template<typename Head, typename... Values>
0116 class get_impl<0, tuple<Head, Values...> >
0117 {
0118    public:
0119    typedef typename add_reference<Head>::type         type;
0120    typedef typename add_const_reference<Head>::type   const_type;
0121    static type       get(tuple<Head, Values...>& t)      { return t.head(); }
0122    static const_type get(const tuple<Head, Values...>& t){ return t.head(); }
0123 };
0124 
0125 template<int I, typename... Values>
0126 typename get_impl<I, tuple<Values...> >::type get(tuple<Values...>& t)
0127 {  return get_impl<I, tuple<Values...> >::get(t);  }
0128 
0129 template<int I, typename... Values>
0130 typename get_impl<I, tuple<Values...> >::const_type get(const tuple<Values...>& t)
0131 {  return get_impl<I, tuple<Values...> >::get(t);  }
0132 
0133 ////////////////////////////////////////////////////
0134 // Builds an index_tuple<0, 1, 2, ..., Num-1>, that will
0135 // be used to "unpack" into comma-separated values
0136 // in a function call.
0137 ////////////////////////////////////////////////////
0138 
0139 template<std::size_t...> struct index_tuple{ typedef index_tuple type; };
0140 
0141 template<class S1, class S2> struct concat_index_tuple;
0142 
0143 template<std::size_t... I1, std::size_t... I2>
0144 struct concat_index_tuple<index_tuple<I1...>, index_tuple<I2...>>
0145   : index_tuple<I1..., (sizeof...(I1)+I2)...>{};
0146 
0147 template<std::size_t N> struct build_number_seq;
0148 
0149 template<std::size_t N> 
0150 struct build_number_seq
0151    : concat_index_tuple<typename build_number_seq<N/2>::type
0152                        ,typename build_number_seq<N - N/2 >::type
0153    >::type
0154 {};
0155 
0156 template<> struct build_number_seq<0> : index_tuple<>{};
0157 template<> struct build_number_seq<1> : index_tuple<0>{};
0158 
0159 }}}   //namespace boost { namespace container { namespace dtl {
0160 
0161 #include <boost/container/detail/config_end.hpp>
0162 
0163 #endif   //#ifndef BOOST_CONTAINER_DETAIL_VARIADIC_TEMPLATES_TOOLS_HPP