repeat_while¶
Header¶
#include <boost/hof/repeat_while.hpp>
Description¶
The repeat_while function decorator will repeatedly apply a function while
the predicate returns a boolean that is true. If the predicate returns an
IntergralConstant then the predicate is only evaluated at compile-time.
Synopsis¶
template<class Predicate>
constexpr auto repeat_while(Predicate predicate);
Example¶
#include <boost/hof.hpp>
#include <cassert>
struct increment
{
    template<class T>
    constexpr std::integral_constant<int, T::value + 1> operator()(T) const
    {
        return std::integral_constant<int, T::value + 1>();
    }
};
struct not_6
{
    template<class T>
    constexpr std::integral_constant<bool, (T::value != 6)> 
    operator()(T) const
    {
        return std::integral_constant<bool, (T::value != 6)>();
    }
};
typedef std::integral_constant<int, 1> one;
typedef std::integral_constant<int, 6> six;
int main() {
    auto increment_until_6 = boost::hof::repeat_while(not_6())(increment());
    static_assert(std::is_same<six, decltype(increment_until_6(one()))>::value, "Error");
}




