C++ Template Metaprogramming
Solutions to the exercises throughout the book
Loading...
Searching...
No Matches
exercise_6_1::binary< N > Struct Template Reference

Compile-time binary to decimal number translation. More...

#include <exercise-6-1.hpp>

Classes

struct  apply_binary_digit
 Mathematics used by accumulate is broken out for clarity... More...
 
struct  apply_binary_digit< T1, binary< N2 > >
 Specialization so we can get direct access to the binary numebr. More...
 

Public Types

typedef binary_tag tag
 
typedef boost::mpl::forward_iterator_tag category
 
typedef boost::mpl::accumulate< binary< N >, boost::mpl::int_< 0 >, apply_binary_digit< _, _ > >::type type
 Iterate across the digits, building a decimal result.
 

Static Public Attributes

static int const value = type::value
 The computed result as a constant value.
 

Detailed Description

template<unsigned long N>
struct exercise_6_1::binary< N >

Compile-time binary to decimal number translation.

Technically, you can actually traverse binary<N> as a sequence with the metafunctions, boost::mpl::begin, etc. Each iterator wraps a single digit in the binary number (0 or 1 – no powers of 2 to indicate the significance of the digit).

Template Parameters
NA binary number to examine. Obvisouly, this should contain only 0 and 1.

Definition at line 131 of file exercise-6-1.hpp.

Member Typedef Documentation

◆ category

template<unsigned long N>
typedef boost::mpl::forward_iterator_tag exercise_6_1::binary< N >::category

Definition at line 136 of file exercise-6-1.hpp.

◆ tag

template<unsigned long N>
typedef binary_tag exercise_6_1::binary< N >::tag

Definition at line 133 of file exercise-6-1.hpp.

◆ type

template<unsigned long N>
typedef boost::mpl::accumulate<binary<N>,boost::mpl::int_<0>,apply_binary_digit<_,_>>::type exercise_6_1::binary< N >::type

Iterate across the digits, building a decimal result.

Definition at line 161 of file exercise-6-1.hpp.

Member Data Documentation

◆ value

template<unsigned long N>
int const exercise_6_1::binary< N >::value = type::value
static

The computed result as a constant value.

Definition at line 164 of file exercise-6-1.hpp.


The documentation for this struct was generated from the following file: