blob: 1281419ec84cef27a2503b6b86fec0c8517d6451 [file] [log] [blame]
Jeff Thompsona28eed82013-08-22 16:21:10 -07001//////////////////////////////////////////////////////////////////////////////
2//
3// (C) Copyright Ion Gaztanaga 2005-2012.
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9// See http://www.boost.org/libs/container for documentation.
10//
11//////////////////////////////////////////////////////////////////////////////
12
13#ifndef BOOST_CONTAINER_CONTAINER_DETAIL_MPL_HPP
14#define BOOST_CONTAINER_CONTAINER_DETAIL_MPL_HPP
15
16#if (defined _MSC_VER) && (_MSC_VER >= 1200)
17# pragma once
18#endif
19
20#include <cstddef>
21
22namespace ndnboost {
23namespace container {
24namespace container_detail {
25
26template <class T, T val>
27struct integral_constant
28{
29 static const T value = val;
30 typedef integral_constant<T,val> type;
31};
32
33template< bool C_ >
34struct bool_ : integral_constant<bool, C_>
35{
36 static const bool value = C_;
37 operator bool() const { return bool_::value; }
38};
39
40typedef bool_<true> true_;
41typedef bool_<false> false_;
42
43typedef true_ true_type;
44typedef false_ false_type;
45
46typedef char yes_type;
47struct no_type
48{
49 char padding[8];
50};
51
52template <bool B, class T = void>
53struct enable_if_c {
54 typedef T type;
55};
56
57template <class T>
58struct enable_if_c<false, T> {};
59
60template <class Cond, class T = void>
61struct enable_if : public enable_if_c<Cond::value, T> {};
62
63template <class Cond, class T = void>
64struct disable_if : public enable_if_c<!Cond::value, T> {};
65
66template <bool B, class T = void>
67struct disable_if_c : public enable_if_c<!B, T> {};
68
69template <class T, class U>
70class is_convertible
71{
72 typedef char true_t;
73 class false_t { char dummy[2]; };
74 static true_t dispatch(U);
75 static false_t dispatch(...);
76 static T trigger();
77 public:
78 enum { value = sizeof(dispatch(trigger())) == sizeof(true_t) };
79};
80
81template<
82 bool C
83 , typename T1
84 , typename T2
85 >
86struct if_c
87{
88 typedef T1 type;
89};
90
91template<
92 typename T1
93 , typename T2
94 >
95struct if_c<false,T1,T2>
96{
97 typedef T2 type;
98};
99
100template<
101 typename T1
102 , typename T2
103 , typename T3
104 >
105struct if_
106{
107 typedef typename if_c<0 != T1::value, T2, T3>::type type;
108};
109
110
111template <class Pair>
112struct select1st
113// : public std::unary_function<Pair, typename Pair::first_type>
114{
115 template<class OtherPair>
116 const typename Pair::first_type& operator()(const OtherPair& x) const
117 { return x.first; }
118
119 const typename Pair::first_type& operator()(const typename Pair::first_type& x) const
120 { return x; }
121};
122
123// identity is an extension: it is not part of the standard.
124template <class T>
125struct identity
126// : public std::unary_function<T,T>
127{
128 typedef T type;
129 const T& operator()(const T& x) const
130 { return x; }
131};
132
133template<std::size_t S>
134struct ls_zeros
135{
136 static const std::size_t value = (S & std::size_t(1)) ? 0 : (1u + ls_zeros<(S >> 1u)>::value);
137};
138
139template<>
140struct ls_zeros<0>
141{
142 static const std::size_t value = 0;
143};
144
145template<>
146struct ls_zeros<1>
147{
148 static const std::size_t value = 0;
149};
150
151template <typename T> struct unvoid { typedef T type; };
152template <> struct unvoid<void> { struct type { }; };
153template <> struct unvoid<const void> { struct type { }; };
154
155} //namespace container_detail {
156} //namespace container {
157} //namespace ndnboost {
158
159#endif //#ifndef BOOST_CONTAINER_CONTAINER_DETAIL_MPL_HPP
160