My question is simple, see example:
std::array<int,6> a = {{0,1,2,3,4,5}}; // -- given container. auto F = []( int i ) { return i*i; }; // -- given function. std::vector<int> v; // need create // my solution: v.reserve( a.size () ); for( std::size_t i = 0; i < a.size(); ++i ) v.push_back( F(a[i]) ); // but I need something like std::vector<int>v( a.begin(), a.end(), <|applying each element to F|> ); Can I create container something like above not calling reserve explicitly and any reallocation?
EDIT:
- I want avoid reserve; because othercase my first solution is good for me :)
- I want avoid any resize; because it's initialzed each element by default ctor.
- I will use this in the real project which may included many 3-rd party libraries ( boost, Soft-STL, ...).
std::transformnot do this?transform iteratorsmight be of use here.