Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

digit_to_int

Synopsis

namespace util
{
  template <class D>
  struct digit_to_int;
}

This is a lazy template metafunction that supports currying.

Table 13. Arguments

Name

Type

D

boxed character value


Description

Converts a boxed character containing a value in the range ['0'..'9'] to an integer.

Return value

It returns a boxed integer value.

Header

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

Expression semantics

For any C boxed character value in the range ['0'..'9'] the following expressions are equivalent

digit_to_int<>::apply<C>::type
digit_to_int<C>::type
digit_to_int_c<C::type::value>::type

Example

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

#include <type_traits>

using namespace boost::metaparse;

struct nullary_metafunction_returning_4
{
  using type = std::integral_constant<char, '4'>;
};

static_assert(
  util::digit_to_int<std::integral_constant<char, '0'>>::type::value == 0,
  "it should convert a character to the corresponding integer value"
);

static_assert(
  util::digit_to_int<>::type
    ::apply<std::integral_constant<char, '7'>>::type::value == 7,
  "it should support currying"
);

static_assert(
  util::digit_to_int<nullary_metafunction_returning_4>::type::value == 4,
  "it should support lazy evaluation"
);

PrevUpHomeNext