Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

in_range

Synopsis

namespace util
{
  template <class LowerBound, class UpperBound, class Item>
  struct in_range;
}

This is a template metafunction supporting currying.

Table 41. Arguments

Name

Type

LowerBound

boxed integral value

UpperBound

boxed integral value

Item

boxed integral value


Description

It returns a boxed boolean value. The value is true when Item is in the range [LowerBound..UpperBound] and false otherwise. boost::mpl::less_equal is used for comparison.

Header

#include <boost/metaparse/util/in_range.hpp>

Expression semantics

For any L, U and T classes the following are equivalent:

in_range<L, U>::apply<T>::type::value

boost::mpl::less_equal<L, T>::type::value
  && boost::mpl::less_equal<T, U>::type::value

Example

#include <boost/metaparse/util/in_range.hpp>

#include <boost/mpl/int.hpp>

using namespace boost::metaparse;

static_assert(
  !util::in_range<
    boost::mpl::int_<11>,
    boost::mpl::int_<13>,
    boost::mpl::int_<10>
  >::type::value,
  "A value below the lower bound should not be in the range"
);

static_assert(
  !util::in_range<
    boost::mpl::int_<11>,
    boost::mpl::int_<13>,
    boost::mpl::int_<14>
  >::type::value,
  "A value above the upper bound should not be in the range"
);

static_assert(
  util::in_range<
    boost::mpl::int_<11>,
    boost::mpl::int_<13>,
    boost::mpl::int_<11>
  >::type::value,
  "The lower bound should be in the range"
);

static_assert(
  util::in_range<
    boost::mpl::int_<11>,
    boost::mpl::int_<13>,
    boost::mpl::int_<13>
  >::type::value,
  "The upper bound should be in the range"
);

static_assert(
  util::in_range<
    boost::mpl::int_<11>,
    boost::mpl::int_<13>,
    boost::mpl::int_<12>
  >::type::value,
  "A value between the bounds should be in the range"
);

static_assert(
  util::in_range<>
    ::apply<boost::mpl::int_<11>>::type
    ::apply<boost::mpl::int_<13>>::type
    ::apply<boost::mpl::int_<12>>::type
    ::type::value,
  "It should support currying"
);

PrevUpHomeNext