define_adaptor.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Boost.Range library
  2. //
  3. // Copyright Neil Groves 2010. Use, modification and
  4. // distribution is subject to the Boost Software License, Version
  5. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // For more information, see http://www.boost.org/libs/range/
  9. //
  10. #ifndef BOOST_RANGE_DEFINE_ADAPTOR_HPP_INCLUDED
  11. #define BOOST_RANGE_DEFINE_ADAPTOR_HPP_INCLUDED
  12. #include <boost/tuple/tuple.hpp>
  13. #define BOOST_DEFINE_RANGE_ADAPTOR( adaptor_name, range_adaptor ) \
  14. struct adaptor_name##_forwarder {}; \
  15. \
  16. template<typename Range> range_adaptor <Range> \
  17. operator|(Range& rng, adaptor_name##_forwarder) \
  18. { \
  19. return range_adaptor <Range>( rng ); \
  20. } \
  21. \
  22. template<typename Range> range_adaptor <const Range> \
  23. operator|(const Range& rng, adaptor_name##_forwarder) \
  24. { \
  25. return range_adaptor <const Range>( rng ); \
  26. } \
  27. \
  28. static adaptor_name##_forwarder adaptor_name = adaptor_name##_forwarder(); \
  29. \
  30. template<typename Range> \
  31. range_adaptor <Range> \
  32. make_##adaptor_name(Range& rng) \
  33. { \
  34. return range_adaptor <Range>(rng); \
  35. } \
  36. \
  37. template<typename Range> \
  38. range_adaptor <const Range> \
  39. make_##adaptor_name(const Range& rng) \
  40. { \
  41. return range_adaptor <const Range>(rng); \
  42. }
  43. #define BOOST_DEFINE_RANGE_ADAPTOR_1( adaptor_name, range_adaptor, arg1_type ) \
  44. struct adaptor_name \
  45. { \
  46. explicit adaptor_name (arg1_type arg1_) \
  47. : arg1(arg1_) {} \
  48. arg1_type arg1; \
  49. }; \
  50. \
  51. template<typename Range> range_adaptor <Range> \
  52. operator|(Range& rng, adaptor_name args) \
  53. { \
  54. return range_adaptor <Range>(rng, args.arg1); \
  55. } \
  56. \
  57. template<typename Range> range_adaptor <const Range> \
  58. operator|(const Range& rng, adaptor_name args) \
  59. { \
  60. return range_adaptor <const Range>(rng, args.arg1); \
  61. } \
  62. \
  63. template<typename Range> \
  64. range_adaptor <Range> \
  65. make_##adaptor_name(Range& rng, arg1_type arg1) \
  66. { \
  67. return range_adaptor <Range>(rng, arg1); \
  68. } \
  69. \
  70. template<typename Range> \
  71. range_adaptor <const Range> \
  72. make_##adaptor_name(const Range& rng, arg1_type arg1) \
  73. { \
  74. return range_adaptor <const Range>(rng, arg1); \
  75. }
  76. #define BOOST_RANGE_ADAPTOR_2( adaptor_name, range_adaptor, arg1_type, arg2_type ) \
  77. struct adaptor_name \
  78. { \
  79. explicit adaptor_name (arg1_type arg1_, arg2_type arg2_) \
  80. : arg1(arg1_), arg2(arg2_) {} \
  81. arg1_type arg1; \
  82. arg2_type arg2; \
  83. }; \
  84. \
  85. template<typename Range> range_adaptor <Range> \
  86. operator|(Range& rng, adaptor_name args) \
  87. { \
  88. return range_adaptor <Range>(rng, args.arg1, args.arg2); \
  89. } \
  90. template<typename Range> \
  91. range_adaptor <Range> \
  92. make_##adaptor_name(Range& rng, arg1_type arg1, arg2_type arg2) \
  93. { \
  94. return range_adaptor <Range>(rng, arg1, arg2); \
  95. } \
  96. template<typename Range> \
  97. range_adaptor <const Range> \
  98. make_##adaptor_name(const Range& rng, arg1_type arg1, arg2_type arg2) \
  99. { \
  100. return range_adaptor <const Range>(rng, arg1, arg2); \
  101. }
  102. #endif // include guard