fix doc example typo
[boost.git] / boost / interprocess / detail / mpl.hpp
blob364a54dbed499af07ac55fac6d791f6881511260
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2005-2008.
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/interprocess for documentation.
11 //////////////////////////////////////////////////////////////////////////////
13 #ifndef BOOST_INTERPROCESS_DETAIL_MPL_HPP
14 #define BOOST_INTERPROCESS_DETAIL_MPL_HPP
16 #if (defined _MSC_VER) && (_MSC_VER >= 1200)
17 # pragma once
18 #endif
20 #include <cstddef>
22 namespace boost {
23 namespace interprocess {
24 namespace detail {
26 template <class T, T val>
27 struct integral_constant
29 static const T value = val;
30 typedef integral_constant<T,val> type;
33 template< bool C_ >
34 struct bool_ : integral_constant<bool, C_>
36 static const bool value = C_;
39 typedef bool_<true> true_;
40 typedef bool_<false> false_;
42 typedef true_ true_type;
43 typedef false_ false_type;
45 typedef char yes_type;
46 struct no_type
48 char padding[8];
51 template <bool B, class T = void>
52 struct enable_if_c {
53 typedef T type;
56 template <class T>
57 struct enable_if_c<false, T> {};
59 template <class Cond, class T = void>
60 struct enable_if : public enable_if_c<Cond::value, T> {};
62 template <class Cond, class T = void>
63 struct disable_if : public enable_if_c<!Cond::value, T> {};
65 template <class T, class U>
66 class is_convertible
68 typedef char true_t;
69 class false_t { char dummy[2]; };
70 static true_t dispatch(U);
71 static false_t dispatch(...);
72 static T trigger();
73 public:
74 enum { value = sizeof(dispatch(trigger())) == sizeof(true_t) };
77 template<
78 bool C
79 , typename T1
80 , typename T2
82 struct if_c
84 typedef T1 type;
87 template<
88 typename T1
89 , typename T2
91 struct if_c<false,T1,T2>
93 typedef T2 type;
96 template<
97 typename T1
98 , typename T2
99 , typename T3
101 struct if_
103 typedef typename if_c<0 != T1::value, T2, T3>::type type;
107 template <class Pair>
108 struct select1st
109 // : public std::unary_function<Pair, typename Pair::first_type>
111 template<class OtherPair>
112 const typename Pair::first_type& operator()(const OtherPair& x) const
113 { return x.first; }
115 const typename Pair::first_type& operator()(const typename Pair::first_type& x) const
116 { return x; }
119 // identity is an extension: it is not part of the standard.
120 template <class T>
121 struct identity
122 // : public std::unary_function<T,T>
124 typedef T type;
125 const T& operator()(const T& x) const
126 { return x; }
129 template<std::size_t S>
130 struct ls_zeros
132 static const std::size_t value = (S & std::size_t(1)) ? 0 : (1u + ls_zeros<(S >> 1u)>::value);
135 template<>
136 struct ls_zeros<0>
138 static const std::size_t value = 0;
141 template<>
142 struct ls_zeros<1>
144 static const std::size_t value = 0;
147 } //namespace detail {
148 } //namespace interprocess {
149 } //namespace boost {
151 #endif //#ifndef BOOST_INTERPROCESS_DETAIL_MPL_HPP