[Range] Help with syntax

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[Range] Help with syntax

Boost - Users mailing list
Given

struct S { int i( ) const; };
vector<S> v;
set<int> s;

I want to write (approximately)

for_each( v | transform( []( const S & s ){ return s.i( ); } ), s.emplace );

With the intention putting all the i's extracted from v into the set s.  My syntax
is all over the place, and I'm not sure how to express the s.emplace bit.

Also is there a better way to say the whole thing? If I were doing push_back instead
of emplace there's a facility especially for that, but I guess Boost::Range hasn't
embraced emplace because range-v3 is around now.

I'm sure some of you are fluent in this stuff!

Kind Regards

Rob.


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [Range] Help with syntax

Boost - Users mailing list
Something like that ? 
struct classcomp {
bool operator() ( const S &  & lhs, const S& rhs) const
{return lhs.i( )< rhs.i( );} 
}; 
set<int, classcomp> s(v.begin(), v.end());

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [Range] Help with syntax

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
I think you are looking for something like this:

std::transform(
  v.begin(),
  v.end(),
  std::inserter(s, s.end()),
  std::mem_fn(&S::i)
);


On Thu, Oct 18, 2018 at 11:02 AM Robert Jones via Boost-users <[hidden email]> wrote:
Given

struct S { int i( ) const; };
vector<S> v;
set<int> s;

I want to write (approximately)

for_each( v | transform( []( const S & s ){ return s.i( ); } ), s.emplace );

With the intention putting all the i's extracted from v into the set s.  My syntax
is all over the place, and I'm not sure how to express the s.emplace bit.

Also is there a better way to say the whole thing? If I were doing push_back instead
of emplace there's a facility especially for that, but I guess Boost::Range hasn't
embraced emplace because range-v3 is around now.

I'm sure some of you are fluent in this stuff!

Kind Regards

Rob.

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users


--
Juan
:wq


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users