c++ - Best way to do flattening of nested getter result inside getter -


sometimes have task of finding if nested getter inside value returned getter has property. classic c++ like:

for (const auto& label: labels)    (const auto& artist: label.artists())      if (artist.name = "arcade fire")        return true; return false; 

what best way ranges? think may work:

 labels|  transform (&label::artists) | join | transform(&artist::name) | join | find_if_fn([](){/*...*/}) ; 

but quite long, (partially because instead of .member_fn must write class:member_fn. there shorter way this?

i think this:

using namespace ranges; auto rng = labels | view::transform(&label::artists) | view::join; return find(rng, "arcade fire", &artist::name) != end(rng); 

gets job done in straightforward way. view::filter formulation:

using namespace ranges; auto rng = labels | view::transform(&label::artists) | view::join |     view::filter([](const artist& a){ return a.name() == "arcade fire"; }); return !empty(rng); 

is bit wordier, has similar performance. it's clear how generalize "is there foo?" "return of foos."


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -