boostorg / boostorg/range

Dedicated adaptor fetching data from an object member

Open
#115 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
45
Forks
104
PR merge metrics
No merged PRs in 30d

Description

In order to make code even more easily readable, I started encapsulating the creation of a "transform" range adaptor that accesses a member variable:

inline constexpr auto fetch = [](auto memberPtr)
{
return boost::adaptors::transformed(std::bind(memberPtr, std::placeholders::_1));
};

// example
sort(c | fetch(&Object::name));

This solves the boiler-plate code required otherwise:

sort(c | transformed(std::bind(&Object::name, std::placeholders::_1)));

Do you think this is a generic enough pattern worthwhile to be added to "boost range"?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.