Bug #160

TDD Reports Operator == for int

Added by Thomas Corbat about 1 month ago.

Status:NewStart date:21 Feb 2017
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:-
Target version:-

Description

constexpr unsigned long long ten_to(size_t n) {
  size_t res = 1;
  while (n-- > 0) res *= 10;
  return res;
}

template<char...> struct parse_digits;

template<>
struct parse_digits<> : std::integral_constant<unsigned long long, 0>{};

template <char D, char... DIGITS>
struct parse_digits<D, DIGITS...>
    : std::integral_constant<unsigned long long, (D - '0') * ten_to(sizeof...(DIGITS)) +
                                                 parse_digits<DIGITS...>{}
>{};

static_assert(123 == parse_digits<'1', '2', '3'>{}, "characters '1', '2' and '3' should be 123");

Also available in: Atom PDF