annotate DEPENDENCIES/generic/include/boost/intrusive/pack_options.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents f46d142149f5
children
rev   line source
Chris@102 1 /////////////////////////////////////////////////////////////////////////////
Chris@102 2 //
Chris@102 3 // (C) Copyright Ion Gaztanaga 2013-2013
Chris@102 4 //
Chris@102 5 // Distributed under the Boost Software License, Version 1.0.
Chris@102 6 // (See accompanying file LICENSE_1_0.txt or copy at
Chris@102 7 // http://www.boost.org/LICENSE_1_0.txt)
Chris@102 8 //
Chris@102 9 // See http://www.boost.org/libs/intrusive for documentation.
Chris@102 10 //
Chris@102 11 /////////////////////////////////////////////////////////////////////////////
Chris@102 12
Chris@102 13 #ifndef BOOST_INTRUSIVE_PACK_OPTIONS_HPP
Chris@102 14 #define BOOST_INTRUSIVE_PACK_OPTIONS_HPP
Chris@102 15
Chris@102 16 #include <boost/intrusive/detail/config_begin.hpp>
Chris@102 17
Chris@102 18 #if defined(BOOST_HAS_PRAGMA_ONCE)
Chris@102 19 # pragma once
Chris@102 20 #endif
Chris@102 21
Chris@102 22 namespace boost {
Chris@102 23 namespace intrusive {
Chris@102 24
Chris@102 25 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
Chris@102 26
Chris@102 27 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
Chris@102 28
Chris@102 29 template<class Prev, class Next>
Chris@102 30 struct do_pack
Chris@102 31 {
Chris@102 32 //Use "pack" member template to pack options
Chris@102 33 typedef typename Next::template pack<Prev> type;
Chris@102 34 };
Chris@102 35
Chris@102 36 template<class Prev>
Chris@102 37 struct do_pack<Prev, void>
Chris@102 38 {
Chris@102 39 //Avoid packing "void" to shorten template names
Chris@102 40 typedef Prev type;
Chris@102 41 };
Chris@102 42
Chris@102 43 template
Chris@102 44 < class DefaultOptions
Chris@102 45 , class O1 = void
Chris@102 46 , class O2 = void
Chris@102 47 , class O3 = void
Chris@102 48 , class O4 = void
Chris@102 49 , class O5 = void
Chris@102 50 , class O6 = void
Chris@102 51 , class O7 = void
Chris@102 52 , class O8 = void
Chris@102 53 , class O9 = void
Chris@102 54 , class O10 = void
Chris@102 55 , class O11 = void
Chris@102 56 >
Chris@102 57 struct pack_options
Chris@102 58 {
Chris@102 59 // join options
Chris@102 60 typedef
Chris@102 61 typename do_pack
Chris@102 62 < typename do_pack
Chris@102 63 < typename do_pack
Chris@102 64 < typename do_pack
Chris@102 65 < typename do_pack
Chris@102 66 < typename do_pack
Chris@102 67 < typename do_pack
Chris@102 68 < typename do_pack
Chris@102 69 < typename do_pack
Chris@102 70 < typename do_pack
Chris@102 71 < typename do_pack
Chris@102 72 < DefaultOptions
Chris@102 73 , O1
Chris@102 74 >::type
Chris@102 75 , O2
Chris@102 76 >::type
Chris@102 77 , O3
Chris@102 78 >::type
Chris@102 79 , O4
Chris@102 80 >::type
Chris@102 81 , O5
Chris@102 82 >::type
Chris@102 83 , O6
Chris@102 84 >::type
Chris@102 85 , O7
Chris@102 86 >::type
Chris@102 87 , O8
Chris@102 88 >::type
Chris@102 89 , O9
Chris@102 90 >::type
Chris@102 91 , O10
Chris@102 92 >::type
Chris@102 93 , O11
Chris@102 94 >::type
Chris@102 95 type;
Chris@102 96 };
Chris@102 97 #else
Chris@102 98
Chris@102 99 //index_tuple
Chris@102 100 template<int... Indexes>
Chris@102 101 struct index_tuple{};
Chris@102 102
Chris@102 103 //build_number_seq
Chris@102 104 template<std::size_t Num, typename Tuple = index_tuple<> >
Chris@102 105 struct build_number_seq;
Chris@102 106
Chris@102 107 template<std::size_t Num, int... Indexes>
Chris@102 108 struct build_number_seq<Num, index_tuple<Indexes...> >
Chris@102 109 : build_number_seq<Num - 1, index_tuple<Indexes..., sizeof...(Indexes)> >
Chris@102 110 {};
Chris@102 111
Chris@102 112 template<int... Indexes>
Chris@102 113 struct build_number_seq<0, index_tuple<Indexes...> >
Chris@102 114 { typedef index_tuple<Indexes...> type; };
Chris@102 115
Chris@102 116 template<class ...Types>
Chris@102 117 struct typelist
Chris@102 118 {};
Chris@102 119
Chris@102 120 //invert_typelist
Chris@102 121 template<class T>
Chris@102 122 struct invert_typelist;
Chris@102 123
Chris@102 124 template<int I, typename Tuple>
Chris@102 125 struct typelist_element;
Chris@102 126
Chris@102 127 template<int I, typename Head, typename... Tail>
Chris@102 128 struct typelist_element<I, typelist<Head, Tail...> >
Chris@102 129 {
Chris@102 130 typedef typename typelist_element<I-1, typelist<Tail...> >::type type;
Chris@102 131 };
Chris@102 132
Chris@102 133 template<typename Head, typename... Tail>
Chris@102 134 struct typelist_element<0, typelist<Head, Tail...> >
Chris@102 135 {
Chris@102 136 typedef Head type;
Chris@102 137 };
Chris@102 138
Chris@102 139 template<int ...Ints, class ...Types>
Chris@102 140 typelist<typename typelist_element<(sizeof...(Types) - 1) - Ints, typelist<Types...> >::type...>
Chris@102 141 inverted_typelist(index_tuple<Ints...>, typelist<Types...>)
Chris@102 142 {
Chris@102 143 return typelist<typename typelist_element<(sizeof...(Types) - 1) - Ints, typelist<Types...> >::type...>();
Chris@102 144 }
Chris@102 145
Chris@102 146 //sizeof_typelist
Chris@102 147 template<class Typelist>
Chris@102 148 struct sizeof_typelist;
Chris@102 149
Chris@102 150 template<class ...Types>
Chris@102 151 struct sizeof_typelist< typelist<Types...> >
Chris@102 152 {
Chris@102 153 static const std::size_t value = sizeof...(Types);
Chris@102 154 };
Chris@102 155
Chris@102 156 //invert_typelist_impl
Chris@102 157 template<class Typelist, class Indexes>
Chris@102 158 struct invert_typelist_impl;
Chris@102 159
Chris@102 160
Chris@102 161 template<class Typelist, int ...Ints>
Chris@102 162 struct invert_typelist_impl< Typelist, index_tuple<Ints...> >
Chris@102 163 {
Chris@102 164 static const std::size_t last_idx = sizeof_typelist<Typelist>::value - 1;
Chris@102 165 typedef typelist
Chris@102 166 <typename typelist_element<last_idx - Ints, Typelist>::type...> type;
Chris@102 167 };
Chris@102 168
Chris@102 169 template<class Typelist, int Int>
Chris@102 170 struct invert_typelist_impl< Typelist, index_tuple<Int> >
Chris@102 171 {
Chris@102 172 typedef Typelist type;
Chris@102 173 };
Chris@102 174
Chris@102 175 template<class Typelist>
Chris@102 176 struct invert_typelist_impl< Typelist, index_tuple<> >
Chris@102 177 {
Chris@102 178 typedef Typelist type;
Chris@102 179 };
Chris@102 180
Chris@102 181 //invert_typelist
Chris@102 182 template<class Typelist>
Chris@102 183 struct invert_typelist;
Chris@102 184
Chris@102 185 template<class ...Types>
Chris@102 186 struct invert_typelist< typelist<Types...> >
Chris@102 187 {
Chris@102 188 typedef typelist<Types...> typelist_t;
Chris@102 189 typedef typename build_number_seq<sizeof...(Types)>::type indexes_t;
Chris@102 190 typedef typename invert_typelist_impl<typelist_t, indexes_t>::type type;
Chris@102 191 };
Chris@102 192
Chris@102 193 //Do pack
Chris@102 194 template<class Typelist>
Chris@102 195 struct do_pack;
Chris@102 196
Chris@102 197 template<>
Chris@102 198 struct do_pack<typelist<> >;
Chris@102 199
Chris@102 200 template<class Prev>
Chris@102 201 struct do_pack<typelist<Prev> >
Chris@102 202 {
Chris@102 203 typedef Prev type;
Chris@102 204 };
Chris@102 205
Chris@102 206 template<class Prev, class Last>
Chris@102 207 struct do_pack<typelist<Prev, Last> >
Chris@102 208 {
Chris@102 209 typedef typename Prev::template pack<Last> type;
Chris@102 210 };
Chris@102 211
Chris@102 212 template<class Prev, class ...Others>
Chris@102 213 struct do_pack<typelist<Prev, Others...> >
Chris@102 214 {
Chris@102 215 typedef typename Prev::template pack
Chris@102 216 <typename do_pack<typelist<Others...> >::type> type;
Chris@102 217 };
Chris@102 218
Chris@102 219
Chris@102 220 template<class DefaultOptions, class ...Options>
Chris@102 221 struct pack_options
Chris@102 222 {
Chris@102 223 typedef typelist<DefaultOptions, Options...> typelist_t;
Chris@102 224 typedef typename invert_typelist<typelist_t>::type inverted_typelist;
Chris@102 225 typedef typename do_pack<inverted_typelist>::type type;
Chris@102 226 };
Chris@102 227
Chris@102 228 #endif //!defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
Chris@102 229
Chris@102 230 #define BOOST_INTRUSIVE_OPTION_TYPE(OPTION_NAME, TYPE, TYPEDEF_EXPR, TYPEDEF_NAME) \
Chris@102 231 template< class TYPE> \
Chris@102 232 struct OPTION_NAME \
Chris@102 233 { \
Chris@102 234 template<class Base> \
Chris@102 235 struct pack : Base \
Chris@102 236 { \
Chris@102 237 typedef TYPEDEF_EXPR TYPEDEF_NAME; \
Chris@102 238 }; \
Chris@102 239 }; \
Chris@102 240 //
Chris@102 241
Chris@102 242 #define BOOST_INTRUSIVE_OPTION_CONSTANT(OPTION_NAME, TYPE, VALUE, CONSTANT_NAME) \
Chris@102 243 template< TYPE VALUE> \
Chris@102 244 struct OPTION_NAME \
Chris@102 245 { \
Chris@102 246 template<class Base> \
Chris@102 247 struct pack : Base \
Chris@102 248 { \
Chris@102 249 static const TYPE CONSTANT_NAME = VALUE; \
Chris@102 250 }; \
Chris@102 251 }; \
Chris@102 252 //
Chris@102 253
Chris@102 254 #else //#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
Chris@102 255
Chris@102 256 //! This class is a utility that takes:
Chris@102 257 //! - a default options class defining initial static constant
Chris@102 258 //! and typedefs
Chris@102 259 //! - several options defined with BOOST_INTRUSIVE_OPTION_CONSTANT and
Chris@102 260 //! BOOST_INTRUSIVE_OPTION_TYPE
Chris@102 261 //!
Chris@102 262 //! and packs them together in a new type that defines all options as
Chris@102 263 //! member typedefs or static constant values. Given options of form:
Chris@102 264 //!
Chris@102 265 //! \code
Chris@102 266 //! BOOST_INTRUSIVE_OPTION_TYPE(my_pointer, VoidPointer, VoidPointer, my_pointer_type)
Chris@102 267 //! BOOST_INTRUSIVE_OPTION_CONSTANT(incremental, bool, Enabled, is_incremental)
Chris@102 268 //! \endcode
Chris@102 269 //!
Chris@102 270 //! the following expression
Chris@102 271 //!
Chris@102 272 //! \code
Chris@102 273 //!
Chris@102 274 //! struct default_options
Chris@102 275 //! {
Chris@102 276 //! typedef long int_type;
Chris@102 277 //! static const int int_constant = -1;
Chris@102 278 //! };
Chris@102 279 //!
Chris@102 280 //! pack_options< default_options, my_pointer<void*>, incremental<true> >::type
Chris@102 281 //! \endcode
Chris@102 282 //!
Chris@102 283 //! will create a type that will contain the following typedefs/constants
Chris@102 284 //!
Chris@102 285 //! \code
Chris@102 286 //! struct unspecified_type
Chris@102 287 //! {
Chris@102 288 //! //Default options
Chris@102 289 //! typedef long int_type;
Chris@102 290 //! static const int int_constant = -1;
Chris@102 291 //!
Chris@102 292 //! //Packed options (will ovewrite any default option)
Chris@102 293 //! typedef void* my_pointer_type;
Chris@102 294 //! static const bool is_incremental = true;
Chris@102 295 //! };
Chris@102 296 //! \endcode
Chris@102 297 //!
Chris@102 298 //! If an option is specified in the default options argument and later
Chris@102 299 //! redefined as an option, the last definition will prevail.
Chris@102 300 template<class DefaultOptions, class ...Options>
Chris@102 301 struct pack_options
Chris@102 302 {
Chris@102 303 typedef unspecified_type type;
Chris@102 304 };
Chris@102 305
Chris@102 306 //! Defines an option class of name OPTION_NAME that can be used to specify a type
Chris@102 307 //! of type TYPE...
Chris@102 308 //!
Chris@102 309 //! \code
Chris@102 310 //! struct OPTION_NAME<class TYPE>
Chris@102 311 //! { unspecified_content };
Chris@102 312 //! \endcode
Chris@102 313 //!
Chris@102 314 //! ...that after being combined with
Chris@102 315 //! <code>boost::intrusive::pack_options</code>,
Chris@102 316 //! will typedef TYPE as a typedef of name TYPEDEF_NAME. Example:
Chris@102 317 //!
Chris@102 318 //! \code
Chris@102 319 //! //[includes and namespaces omitted for brevity]
Chris@102 320 //!
Chris@102 321 //! //This macro will create the following class:
Chris@102 322 //! // template<class VoidPointer>
Chris@102 323 //! // struct my_pointer
Chris@102 324 //! // { unspecified_content };
Chris@102 325 //! BOOST_INTRUSIVE_OPTION_TYPE(my_pointer, VoidPointer, boost::remove_pointer<VoidPointer>::type, my_pointer_type)
Chris@102 326 //!
Chris@102 327 //! struct empty_default{};
Chris@102 328 //!
Chris@102 329 //! typedef pack_options< empty_default, typename my_pointer<void*> >::type::my_pointer_type type;
Chris@102 330 //!
Chris@102 331 //! BOOST_STATIC_ASSERT(( boost::is_same<type, void>::value ));
Chris@102 332 //!
Chris@102 333 //! \endcode
Chris@102 334 #define BOOST_INTRUSIVE_OPTION_TYPE(OPTION_NAME, TYPE, TYPEDEF_EXPR, TYPEDEF_NAME)
Chris@102 335
Chris@102 336 //! Defines an option class of name OPTION_NAME that can be used to specify a constant
Chris@102 337 //! of type TYPE with value VALUE...
Chris@102 338 //!
Chris@102 339 //! \code
Chris@102 340 //! struct OPTION_NAME<TYPE VALUE>
Chris@102 341 //! { unspecified_content };
Chris@102 342 //! \endcode
Chris@102 343 //!
Chris@102 344 //! ...that after being combined with
Chris@102 345 //! <code>boost::intrusive::pack_options</code>,
Chris@102 346 //! will contain a CONSTANT_NAME static constant of value VALUE. Example:
Chris@102 347 //!
Chris@102 348 //! \code
Chris@102 349 //! //[includes and namespaces omitted for brevity]
Chris@102 350 //!
Chris@102 351 //! //This macro will create the following class:
Chris@102 352 //! // template<bool Enabled>
Chris@102 353 //! // struct incremental
Chris@102 354 //! // { unspecified_content };
Chris@102 355 //! BOOST_INTRUSIVE_OPTION_CONSTANT(incremental, bool, Enabled, is_incremental)
Chris@102 356 //!
Chris@102 357 //! struct empty_default{};
Chris@102 358 //!
Chris@102 359 //! const bool is_incremental = pack_options< empty_default, incremental<true> >::type::is_incremental;
Chris@102 360 //!
Chris@102 361 //! BOOST_STATIC_ASSERT(( is_incremental == true ));
Chris@102 362 //!
Chris@102 363 //! \endcode
Chris@102 364 #define BOOST_INTRUSIVE_OPTION_CONSTANT(OPTION_NAME, TYPE, VALUE, CONSTANT_NAME)
Chris@102 365
Chris@102 366 #endif //#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
Chris@102 367
Chris@102 368
Chris@102 369 } //namespace intrusive {
Chris@102 370 } //namespace boost {
Chris@102 371
Chris@102 372 #include <boost/intrusive/detail/config_end.hpp>
Chris@102 373
Chris@102 374 #endif //#ifndef BOOST_INTRUSIVE_PACK_OPTIONS_HPP