Skip to content

HowTo write a View add number_smaller

Hannes Hauswedell edited this page Mar 2, 2018 · 1 revision

view_add_number

This can be omitted.

add_number_fn

struct add_number_fn
{
    template <typename irng_t>
//         requires (bool)ranges::InputRange<irng_t>() &&
//                  std::is_same_v<std::decay_t<ranges::range_reference_t<irng_t>>, uint64_t>
    auto operator()(irng_t && irange, uint64_t const the_number) const
    {
        return ranges::view::transform(std::forward<irng_t>(irange), [=] (uint64_t const in) {return in + the_number;});
    }
  • We can delegate to the transform view here.
    auto operator()(uint64_t const the_number) const
    {
        return std::bind(add_number_fn(), std::placeholders::_1, the_number);
    }

};

template <typename irng_t>
//         requires (bool)ranges::InputRange<irng_t>() &&
//                  std::is_same_v<std::decay_t<ranges::range_reference_t<irng_t>>, uint64_t>
auto operator|(irng_t && irange, decltype(std::bind(add_number_fn(),
                                                    std::placeholders::_1,
                                                    static_cast<uint64_t const &>(0))) const & bound_view)  
{
    return bound_view(std::forward<irng_t>(irange));
}

This rest remains unchanged. Note that it is not (easily) possible to replace the functor creation anymore.

Clone this wiki locally