C++ UFCS update

krzaq via Digitalmars-d digitalmars-d at puremagic.com
Tue Feb 16 23:49:32 PST 2016


On Tuesday, 16 February 2016 at 11:08:28 UTC, Timon Gehr wrote:
> On 16.02.2016 11:21, krzaq wrote:
>>
>> By the way, your example in C++ would be even worse:
>>
>> auto sum_of_filtered = x
>>      .map([&](auto&& val){ foo(val); })
>>      .filter([](auto&& val){ return is_bar(val); })
>>      .reduce(std::plus<>{});
>>
>> vs
>>
>> auto sum_of_filtered =
>> reduce(filter(map(x, [&](auto&& val){ foo(val); }) ,[](auto&& 
>> val){
>> return is_bar(val); }), std::plus<>{});
>
> auto sum_of_filtered = x >>=
>   map([&](auto&& val){ return foo(val); })
> | filter([](auto&& val){ return is_bar(val); })
> | reduce(std::plus<>{});

This will only work with stream-aware functions. That might've 
been your intention, but to me it's only the next best thing. 
Additionally, adding IDE code completion will be pretty difficult 
here.


More information about the Digitalmars-d mailing list