Posts

Showing posts with the label std-ranges

Vector initialisation using ranges vs lambda inline initialisation

10 3 I would like to initialise a vector by transforming the other one. I made a test with two ways of inline initialisation a transformed std::vector . One using lambda inline initialisation (with std::transform ): std::vector<int> foo(100,42); const auto fooTimesTwo = [&]{ std::vector<int> tmp(foo.size()); std::transform(foo.begin(), foo.end(), tmp.begin(), convert); return tmp; }(); And the other one - using std::ranges::views::transform : std::vector<int> foo(100,42); auto transform_range = (foo | std::ranges::views::transform(convert)); std::vector<int> fooTimesTwo { transform_range.begin(), transform_range.end() }; I expected that both way of vector ini...