select.hpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
  2. // (C) Copyright 2003-2007 Jonathan Turkanis
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
  5. // See http://www.boost.org/libs/iostreams for documentation.
  6. // Contains the metafunction select, which mimics the effect of a chain of
  7. // nested mpl if_'s.
  8. //
  9. // -----------------------------------------------------------------------------
  10. //
  11. // Usage:
  12. //
  13. // typedef typename select<
  14. // case1, type1,
  15. // case2, type2,
  16. // ...
  17. // true_, typen
  18. // >::type selection;
  19. //
  20. // Here case1, case2, ... are models of MPL::IntegralConstant with value type
  21. // bool, and n <= 12.
  22. #ifndef BOOST_IOSTREAMS_SELECT_HPP_INCLUDED
  23. #define BOOST_IOSTREAMS_SELECT_HPP_INCLUDED
  24. #if defined(_MSC_VER)
  25. # pragma once
  26. #endif
  27. #include <boost/type_traits/is_base_and_derived.hpp>
  28. #include <boost/mpl/eval_if.hpp>
  29. #include <boost/mpl/identity.hpp>
  30. #include <boost/mpl/if.hpp>
  31. #include <boost/mpl/void.hpp>
  32. namespace boost { namespace iostreams {
  33. typedef mpl::true_ else_;
  34. template< typename Case1 = mpl::true_,
  35. typename Type1 = mpl::void_,
  36. typename Case2 = mpl::true_,
  37. typename Type2 = mpl::void_,
  38. typename Case3 = mpl::true_,
  39. typename Type3 = mpl::void_,
  40. typename Case4 = mpl::true_,
  41. typename Type4 = mpl::void_,
  42. typename Case5 = mpl::true_,
  43. typename Type5 = mpl::void_,
  44. typename Case6 = mpl::true_,
  45. typename Type6 = mpl::void_,
  46. typename Case7 = mpl::true_,
  47. typename Type7 = mpl::void_,
  48. typename Case8 = mpl::true_,
  49. typename Type8 = mpl::void_,
  50. typename Case9 = mpl::true_,
  51. typename Type9 = mpl::void_,
  52. typename Case10 = mpl::true_,
  53. typename Type10 = mpl::void_,
  54. typename Case11 = mpl::true_,
  55. typename Type11 = mpl::void_,
  56. typename Case12 = mpl::true_,
  57. typename Type12 = mpl::void_ >
  58. struct select {
  59. typedef typename
  60. mpl::eval_if<
  61. Case1, mpl::identity<Type1>, mpl::eval_if<
  62. Case2, mpl::identity<Type2>, mpl::eval_if<
  63. Case3, mpl::identity<Type3>, mpl::eval_if<
  64. Case4, mpl::identity<Type4>, mpl::eval_if<
  65. Case5, mpl::identity<Type5>, mpl::eval_if<
  66. Case6, mpl::identity<Type6>, mpl::eval_if<
  67. Case7, mpl::identity<Type7>, mpl::eval_if<
  68. Case8, mpl::identity<Type8>, mpl::eval_if<
  69. Case9, mpl::identity<Type9>, mpl::eval_if<
  70. Case10, mpl::identity<Type10>, mpl::eval_if<
  71. Case11, mpl::identity<Type11>, mpl::if_<
  72. Case12, Type12, mpl::void_ > > > > > > > > > > >
  73. >::type type;
  74. };
  75. } } // End namespaces iostreams, boost.
  76. #endif // #ifndef BOOST_IOSTREAMS_SELECT_HPP_INCLUDED