Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dedicated adaptor fetching data from an object member #115

Open
trueqbit opened this issue Oct 23, 2020 · 0 comments
Open

Dedicated adaptor fetching data from an object member #115

trueqbit opened this issue Oct 23, 2020 · 0 comments

Comments

@trueqbit
Copy link

trueqbit commented Oct 23, 2020

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"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant