C++ Template Metaprogramming
Solutions to the exercises throughout the book
|
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. | |
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).
N | A binary number to examine. Obvisouly, this should contain only 0 and 1. |
Definition at line 131 of file exercise-6-1.hpp.
typedef boost::mpl::forward_iterator_tag exercise_6_1::binary< N >::category |
Definition at line 136 of file exercise-6-1.hpp.
typedef binary_tag exercise_6_1::binary< N >::tag |
Definition at line 133 of file exercise-6-1.hpp.
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.
|
static |
The computed result as a constant value.
Definition at line 164 of file exercise-6-1.hpp.