1 /* Copyright 2003-2014 Joaquin M Lopez Munoz.
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
6 * See http://www.boost.org/libs/multi_index for library home page.
9 #ifndef BOOST_MULTI_INDEX_DETAIL_CONS_STDTUPLE_HPP
10 #define BOOST_MULTI_INDEX_DETAIL_CONS_STDTUPLE_HPP
16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
17 #include <boost/mpl/if.hpp>
18 #include <boost/tuple/tuple.hpp>
23 namespace multi_index{
27 /* std::tuple wrapper providing the cons-based interface of boost::tuple for
28 * composite_key interoperability.
31 template<typename StdTuple,std::size_t N>
34 struct cons_stdtuple_ctor_terminal
36 typedef boost::tuples::null_type result_type;
38 template<typename StdTuple>
39 static result_type create(const StdTuple&)
41 return boost::tuples::null_type();
45 template<typename StdTuple,std::size_t N>
46 struct cons_stdtuple_ctor_normal
48 typedef cons_stdtuple<StdTuple,N> result_type;
50 static result_type create(const StdTuple& t)
52 return result_type(t);
56 template<typename StdTuple,std::size_t N=0>
57 struct cons_stdtuple_ctor:
59 N<std::tuple_size<StdTuple>::value,
60 cons_stdtuple_ctor_normal<StdTuple,N>,
61 cons_stdtuple_ctor_terminal
65 template<typename StdTuple,std::size_t N>
68 typedef typename std::tuple_element<N,StdTuple>::type head_type;
69 typedef cons_stdtuple_ctor<StdTuple,N+1> tail_ctor;
70 typedef typename tail_ctor::result_type tail_type;
72 cons_stdtuple(const StdTuple& t_):t(t_){}
74 const head_type& get_head()const{return std::get<N>(t);}
75 tail_type get_tail()const{return tail_ctor::create(t);}
80 template<typename StdTuple>
81 typename cons_stdtuple_ctor<StdTuple>::result_type
82 make_cons_stdtuple(const StdTuple& t)
84 return cons_stdtuple_ctor<StdTuple>::create(t);
87 } /* namespace multi_index::detail */
89 } /* namespace multi_index */
91 } /* namespace boost */