C++ Template Metaprogramming
Solutions to the exercises throughout the book
Loading...
Searching...
No Matches
exercise_5_1::double_first_half_impl< S, Res, Cur > Class Template Reference

Represents a single iteration across the sequence. More...

#include <exercise-5-1.hpp>

Public Types

typedef boost::mpl::eval_if< boost::is_same< Cur, typenameboost::mpl::end< S >::type >, Res, double_first_half_impl< S, typenameboost::mpl::push_back< Res, typenamemultiply_or_not::type >::type, typenameboost::mpl::next< Cur >::type > >::type type
 Produce a result and keep iterating until we reach the end.
 

Private Types

typedef boost::mpl::distance< typename boost::mpl::begin< S >::type, Cur > dist_to_begin
 The distance from the beginning of the sequence to where we are.
 
typedef boost::mpl::distance< Cur, typename boost::mpl::end< S >::typedist_to_end
 The distance from the end of the sequence to where we are.
 
typedef boost::mpl::eval_if< boost::mpl::greater_equal< dist_to_begin, dist_to_end >, boost::mpl::deref< Cur >, boost::mpl::times< typename boost::mpl::deref< Cur >::type, boost::mpl::int_< 2 > > > multiply_or_not
 Lazily decide what operation to use if we're past the midpoint.
 

Detailed Description

template<typename S, typename Res, typename Cur>
class exercise_5_1::double_first_half_impl< S, Res, Cur >

Represents a single iteration across the sequence.

This metafunction computes the mid-point, decides what operation to perform on the element, folds the result into the destination, and kicks off the next iteration. This is part of the algorithm for double_first_half.

Template Parameters
SThe input sequence (needed to measure distances).
ResThe resulting sequence.
CurThe iterator to the current location in S.

Definition at line 57 of file exercise-5-1.hpp.

Member Typedef Documentation

◆ dist_to_begin

template<typename S , typename Res , typename Cur >
typedef boost::mpl::distance<typename boost::mpl::begin<S>::type, Cur> exercise_5_1::double_first_half_impl< S, Res, Cur >::dist_to_begin
private

The distance from the beginning of the sequence to where we are.

Definition at line 63 of file exercise-5-1.hpp.

◆ dist_to_end

template<typename S , typename Res , typename Cur >
typedef boost::mpl::distance<Cur, typename boost::mpl::end<S>::type> exercise_5_1::double_first_half_impl< S, Res, Cur >::dist_to_end
private

The distance from the end of the sequence to where we are.

Definition at line 67 of file exercise-5-1.hpp.

◆ multiply_or_not

template<typename S , typename Res , typename Cur >
typedef boost::mpl::eval_if< boost::mpl::greater_equal<dist_to_begin, dist_to_end>, boost::mpl::deref<Cur>, boost::mpl::times< typename boost::mpl::deref<Cur>::type, boost::mpl::int_<2> > > exercise_5_1::double_first_half_impl< S, Res, Cur >::multiply_or_not
private

Lazily decide what operation to use if we're past the midpoint.

Definition at line 78 of file exercise-5-1.hpp.

◆ type

template<typename S , typename Res , typename Cur >
typedef boost::mpl::eval_if<boost::is_same<Cur,typenameboost::mpl::end<S>::type>,Res,double_first_half_impl<S,typenameboost::mpl::push_back<Res,typenamemultiply_or_not::type>::type,typenameboost::mpl::next<Cur>::type>>::type exercise_5_1::double_first_half_impl< S, Res, Cur >::type

Produce a result and keep iterating until we reach the end.

Definition at line 95 of file exercise-5-1.hpp.


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