PageRenderTime 68ms CodeModel.GetById 40ms app.highlight 23ms RepoModel.GetById 2ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/interprocess/containers/container/detail/variadic_templates_tools.hpp

http://hadesmem.googlecode.com/
C++ Header | 153 lines | 102 code | 34 blank | 17 comment | 1 complexity | 0e27d1463fe506c8b52fc27f73562f36 MD5 | raw file
  1//////////////////////////////////////////////////////////////////////////////
  2//
  3// (C) Copyright Ion Gaztanaga 2008-2009. Distributed under the Boost
  4// Software License, Version 1.0. (See accompanying file
  5// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6//
  7// See http://www.boost.org/libs/container for documentation.
  8//
  9//////////////////////////////////////////////////////////////////////////////
 10
 11#ifndef BOOST_CONTAINERS_DETAIL_VARIADIC_TEMPLATES_TOOLS_HPP
 12#define BOOST_CONTAINERS_DETAIL_VARIADIC_TEMPLATES_TOOLS_HPP
 13
 14#if (defined _MSC_VER) && (_MSC_VER >= 1200)
 15#  pragma once
 16#endif
 17
 18#include "config_begin.hpp"
 19#include INCLUDE_BOOST_CONTAINER_DETAIL_WORKAROUND_HPP
 20#include INCLUDE_BOOST_CONTAINER_DETAIL_TYPE_TRAITS_HPP
 21#include <cstddef>   //std::size_t
 22
 23namespace boost {
 24namespace container { 
 25namespace containers_detail {
 26
 27template<typename... Values>
 28class tuple;
 29
 30template<> class tuple<>
 31{};
 32
 33template<typename Head, typename... Tail>
 34class tuple<Head, Tail...>
 35   : private tuple<Tail...>
 36{
 37   typedef tuple<Tail...> inherited;
 38
 39   public:
 40   tuple() { }
 41
 42   // implicit copy-constructor is okay
 43   // Construct tuple from separate arguments.
 44   tuple(typename add_const_reference<Head>::type v,
 45         typename add_const_reference<Tail>::type... vtail)
 46   : inherited(vtail...), m_head(v)
 47   {}
 48
 49   // Construct tuple from another tuple.
 50   template<typename... VValues>
 51   tuple(const tuple<VValues...>& other)
 52      : m_head(other.head()), inherited(other.tail())
 53   {}
 54
 55   template<typename... VValues>
 56   tuple& operator=(const tuple<VValues...>& other)
 57   {
 58      m_head = other.head();
 59      tail() = other.tail();
 60      return this;
 61   }
 62
 63   typename add_reference<Head>::type head()             {  return m_head; }
 64   typename add_reference<const Head>::type head() const {  return m_head; }
 65
 66   inherited& tail()             { return *this; }
 67   const inherited& tail() const { return *this; }
 68
 69   protected:
 70   Head m_head;
 71};
 72
 73
 74template<typename... Values>
 75tuple<Values&&...> tie_forward(Values&&... values)
 76{ return tuple<Values&&...>(values...); }
 77
 78template<int I, typename Tuple>
 79struct tuple_element;
 80
 81template<int I, typename Head, typename... Tail>
 82struct tuple_element<I, tuple<Head, Tail...> >
 83{
 84   typedef typename tuple_element<I-1, tuple<Tail...> >::type type;
 85};
 86
 87template<typename Head, typename... Tail>
 88struct tuple_element<0, tuple<Head, Tail...> >
 89{
 90   typedef Head type;
 91};
 92
 93template<int I, typename Tuple>
 94class get_impl;
 95
 96template<int I, typename Head, typename... Values>
 97class get_impl<I, tuple<Head, Values...> >
 98{
 99   typedef typename tuple_element<I-1, tuple<Values...> >::type   Element;
100   typedef get_impl<I-1, tuple<Values...> >                       Next;
101
102   public:
103   typedef typename add_reference<Element>::type                  type;
104   typedef typename add_const_reference<Element>::type            const_type;
105   static type get(tuple<Head, Values...>& t)              { return Next::get(t.tail()); }
106   static const_type get(const tuple<Head, Values...>& t)  { return Next::get(t.tail()); }
107};
108
109template<typename Head, typename... Values>
110class get_impl<0, tuple<Head, Values...> >
111{
112   public:
113   typedef typename add_reference<Head>::type         type;
114   typedef typename add_const_reference<Head>::type   const_type;
115   static type       get(tuple<Head, Values...>& t)      { return t.head(); }
116   static const_type get(const tuple<Head, Values...>& t){ return t.head(); }
117};
118
119template<int I, typename... Values>
120typename get_impl<I, tuple<Values...> >::type get(tuple<Values...>& t)
121{  return get_impl<I, tuple<Values...> >::get(t);  }
122
123template<int I, typename... Values>
124typename get_impl<I, tuple<Values...> >::const_type get(const tuple<Values...>& t)
125{  return get_impl<I, tuple<Values...> >::get(t);  }
126
127////////////////////////////////////////////////////
128// Builds an index_tuple<0, 1, 2, ..., Num-1>, that will
129// be used to "unpack" into comma-separated values
130// in a function call.
131////////////////////////////////////////////////////
132
133template<int... Indexes>
134struct index_tuple{};
135
136template<std::size_t Num, typename Tuple = index_tuple<> >
137struct build_number_seq;
138
139template<std::size_t Num, int... Indexes> 
140struct build_number_seq<Num, index_tuple<Indexes...> >
141   : build_number_seq<Num - 1, index_tuple<Indexes..., sizeof...(Indexes)> >
142{};
143
144template<int... Indexes>
145struct build_number_seq<0, index_tuple<Indexes...> >
146{  typedef index_tuple<Indexes...> type;  };
147
148
149}}}   //namespace boost { namespace container { namespace containers_detail {
150
151#include INCLUDE_BOOST_CONTAINER_DETAIL_CONFIG_END_HPP
152
153#endif   //#ifndef BOOST_CONTAINERS_DETAIL_VARIADIC_TEMPLATES_TOOLS_HPP