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