in_range.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef BOOST_METAPARSE_V1_UTIL_IN_RANGE_HPP
  2. #define BOOST_METAPARSE_V1_UTIL_IN_RANGE_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2009 - 2010.
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include <boost/mpl/less_equal.hpp>
  8. #include <boost/mpl/comparison.hpp>
  9. #include <boost/mpl/quote.hpp>
  10. #include <boost/mpl/bool.hpp>
  11. #include <boost/mpl/vector.hpp>
  12. namespace boost
  13. {
  14. namespace metaparse
  15. {
  16. namespace v1
  17. {
  18. namespace util
  19. {
  20. template <
  21. class LowerBound = boost::mpl::na,
  22. class UpperBound = boost::mpl::na,
  23. class Item = boost::mpl::na
  24. >
  25. struct in_range :
  26. boost::mpl::bool_<
  27. boost::mpl::less_equal<LowerBound, Item>::type::value
  28. && boost::mpl::less_equal<Item, UpperBound>::type::value
  29. >
  30. {};
  31. template <class LowerBound, class UpperBound>
  32. struct in_range<LowerBound, UpperBound, boost::mpl::na>
  33. {
  34. typedef in_range type;
  35. template <class Item = boost::mpl::na>
  36. struct apply : in_range<LowerBound, UpperBound, Item> {};
  37. };
  38. template <class LowerBound>
  39. struct in_range<LowerBound, boost::mpl::na, boost::mpl::na>
  40. {
  41. typedef in_range type;
  42. template <
  43. class UpperBound = boost::mpl::na,
  44. class Item = boost::mpl::na
  45. >
  46. struct apply : in_range<LowerBound, UpperBound, Item> {};
  47. };
  48. template <>
  49. struct in_range<boost::mpl::na, boost::mpl::na, boost::mpl::na>
  50. {
  51. typedef in_range type;
  52. template <
  53. class LowerBound = boost::mpl::na,
  54. class UpperBound = boost::mpl::na,
  55. class Item = boost::mpl::na
  56. >
  57. struct apply : in_range<LowerBound, UpperBound, Item> {};
  58. };
  59. }
  60. }
  61. }
  62. }
  63. #endif