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

http://hadesmem.googlecode.com/ · C++ Header · 153 lines · 102 code · 34 blank · 17 comment · 1 complexity · c1145bb7eeb8744b87db22d9ef867a5f 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/interprocess for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_INTERPROCESS_DETAIL_VARIADIC_TEMPLATES_TOOLS_HPP
  11. #define BOOST_INTERPROCESS_DETAIL_VARIADIC_TEMPLATES_TOOLS_HPP
  12. #if (defined _MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif
  15. #include <boost/interprocess/detail/config_begin.hpp>
  16. #include <boost/interprocess/detail/workaround.hpp>
  17. #include <boost/interprocess/detail/type_traits.hpp>
  18. #include <cstddef> //std::size_t
  19. namespace boost {
  20. namespace interprocess {
  21. namespace detail {
  22. template<typename... Values>
  23. class tuple;
  24. template<> class tuple<>
  25. {};
  26. template<typename Head, typename... Tail>
  27. class tuple<Head, Tail...>
  28. : private tuple<Tail...>
  29. {
  30. typedef tuple<Tail...> inherited;
  31. public:
  32. tuple() { }
  33. // implicit copy-constructor is okay
  34. // Construct tuple from separate arguments.
  35. tuple(typename add_const_reference<Head>::type v,
  36. typename add_const_reference<Tail>::type... vtail)
  37. : inherited(vtail...), m_head(v)
  38. {}
  39. // Construct tuple from another tuple.
  40. template<typename... VValues>
  41. tuple(const tuple<VValues...>& other)
  42. : m_head(other.head()), inherited(other.tail())
  43. {}
  44. template<typename... VValues>
  45. tuple& operator=(const tuple<VValues...>& other)
  46. {
  47. m_head = other.head();
  48. tail() = other.tail();
  49. return this;
  50. }
  51. typename add_reference<Head>::type head() { return m_head; }
  52. typename add_reference<const Head>::type head() const { return m_head; }
  53. inherited& tail() { return *this; }
  54. const inherited& tail() const { return *this; }
  55. protected:
  56. Head m_head;
  57. };
  58. template<typename... Values>
  59. tuple<Values&&...> tie_forward(Values&&... values)
  60. { return tuple<Values&&...>(values...); }
  61. template<int I, typename Tuple>
  62. struct tuple_element;
  63. template<int I, typename Head, typename... Tail>
  64. struct tuple_element<I, tuple<Head, Tail...> >
  65. {
  66. typedef typename tuple_element<I-1, tuple<Tail...> >::type type;
  67. };
  68. template<typename Head, typename... Tail>
  69. struct tuple_element<0, tuple<Head, Tail...> >
  70. {
  71. typedef Head type;
  72. };
  73. template<int I, typename Tuple>
  74. class get_impl;
  75. template<int I, typename Head, typename... Values>
  76. class get_impl<I, tuple<Head, Values...> >
  77. {
  78. typedef typename tuple_element<I-1, tuple<Values...> >::type Element;
  79. typedef get_impl<I-1, tuple<Values...> > Next;
  80. public:
  81. typedef typename add_reference<Element>::type type;
  82. typedef typename add_const_reference<Element>::type const_type;
  83. static type get(tuple<Head, Values...>& t) { return Next::get(t.tail()); }
  84. static const_type get(const tuple<Head, Values...>& t) { return Next::get(t.tail()); }
  85. };
  86. template<typename Head, typename... Values>
  87. class get_impl<0, tuple<Head, Values...> >
  88. {
  89. public:
  90. typedef typename add_reference<Head>::type type;
  91. typedef typename add_const_reference<Head>::type const_type;
  92. static type get(tuple<Head, Values...>& t) { return t.head(); }
  93. static const_type get(const tuple<Head, Values...>& t){ return t.head(); }
  94. };
  95. template<int I, typename... Values>
  96. typename get_impl<I, tuple<Values...> >::type get(tuple<Values...>& t)
  97. { return get_impl<I, tuple<Values...> >::get(t); }
  98. template<int I, typename... Values>
  99. typename get_impl<I, tuple<Values...> >::const_type get(const tuple<Values...>& t)
  100. { return get_impl<I, tuple<Values...> >::get(t); }
  101. ////////////////////////////////////////////////////
  102. // Builds an index_tuple<0, 1, 2, ..., Num-1>, that will
  103. // be used to "unpack" into comma-separated values
  104. // in a function call.
  105. ////////////////////////////////////////////////////
  106. template<int... Indexes>
  107. struct index_tuple{};
  108. template<std::size_t Num, typename Tuple = index_tuple<> >
  109. struct build_number_seq;
  110. template<std::size_t Num, int... Indexes>
  111. struct build_number_seq<Num, index_tuple<Indexes...> >
  112. : build_number_seq<Num - 1, index_tuple<Indexes..., sizeof...(Indexes)> >
  113. {};
  114. template<int... Indexes>
  115. struct build_number_seq<0, index_tuple<Indexes...> >
  116. { typedef index_tuple<Indexes...> type; };
  117. }}} //namespace boost { namespace interprocess { namespace detail {
  118. #include <boost/interprocess/detail/config_end.hpp>
  119. #endif //#ifndef BOOST_INTERPROCESS_DETAIL_VARIADIC_TEMPLATES_TOOLS_HPP