Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:42:06

0001 /* Copyright 2003-2014 Joaquin M Lopez Munoz.
0002  * Distributed under the Boost Software License, Version 1.0.
0003  * (See accompanying file LICENSE_1_0.txt or copy at
0004  * http://www.boost.org/LICENSE_1_0.txt)
0005  *
0006  * See http://www.boost.org/libs/multi_index for library home page.
0007  */
0008 
0009 #ifndef BOOST_MULTI_INDEX_DETAIL_CONS_STDTUPLE_HPP
0010 #define BOOST_MULTI_INDEX_DETAIL_CONS_STDTUPLE_HPP
0011 
0012 #if defined(_MSC_VER)
0013 #pragma once
0014 #endif
0015 
0016 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
0017 #include <boost/mpl/if.hpp>
0018 #include <boost/tuple/tuple.hpp>
0019 #include <tuple>
0020 
0021 namespace boost{
0022 
0023 namespace multi_index{
0024 
0025 namespace detail{
0026 
0027 /* std::tuple wrapper providing the cons-based interface of boost::tuple for
0028  * composite_key interoperability.
0029  */
0030 
0031 template<typename StdTuple,std::size_t N>
0032 struct cons_stdtuple;
0033 
0034 struct cons_stdtuple_ctor_terminal
0035 {
0036   typedef boost::tuples::null_type result_type;
0037 
0038   template<typename StdTuple>
0039   static result_type create(const StdTuple&)
0040   {
0041     return boost::tuples::null_type();
0042   }
0043 };
0044 
0045 template<typename StdTuple,std::size_t N>
0046 struct cons_stdtuple_ctor_normal
0047 {
0048   typedef cons_stdtuple<StdTuple,N> result_type;
0049 
0050   static result_type create(const StdTuple& t)
0051   {
0052     return result_type(t);
0053   }
0054 };
0055 
0056 template<typename StdTuple,std::size_t N=0>
0057 struct cons_stdtuple_ctor:
0058   boost::mpl::if_c<
0059     N<std::tuple_size<StdTuple>::value,
0060     cons_stdtuple_ctor_normal<StdTuple,N>,
0061     cons_stdtuple_ctor_terminal
0062   >::type
0063 {};
0064 
0065 template<typename StdTuple,std::size_t N>
0066 struct cons_stdtuple
0067 {
0068   typedef typename std::tuple_element<N,StdTuple>::type head_type;
0069   typedef cons_stdtuple_ctor<StdTuple,N+1>              tail_ctor;
0070   typedef typename tail_ctor::result_type               tail_type;
0071   
0072   cons_stdtuple(const StdTuple& t_):t(t_){}
0073 
0074   const head_type& get_head()const{return std::get<N>(t);}
0075   tail_type get_tail()const{return tail_ctor::create(t);}
0076     
0077   const StdTuple& t;
0078 };
0079 
0080 template<typename StdTuple>
0081 typename cons_stdtuple_ctor<StdTuple>::result_type
0082 make_cons_stdtuple(const StdTuple& t)
0083 {
0084   return cons_stdtuple_ctor<StdTuple>::create(t);
0085 }
0086 
0087 } /* namespace multi_index::detail */
0088 
0089 } /* namespace multi_index */
0090 
0091 } /* namespace boost */
0092 
0093 #endif