Opened 10 years ago

Last modified 9 years ago

#7748 closed Feature Requests

Allow explicit result_type specification for transformed — at Version 1

Reported by: nathan.crookston+boost@… Owned by: Neil Groves
Milestone: To Be Determined Component: range
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:

Description (last modified by viboes)

Code like the following doesn't work trunk (and released) transformed:

std::vector<int> myList(...);
float sum = boost::accumulate(myList | transformed([](int a) { return a * 5; }), 0.f);

The following patch & test modifications allow the following syntax:

float sum = boost::accumulate(myList | transformed<float>([](int a) { return a * 5.f; }), 0.f);

This wouldn't be a problem if result_of used or fell back to decltype, but it seems that won't be available for a while. The proposed syntax could also be helpful when using transformed with functors whose implementations are both unmodifiable and don't follow result_of.

Patch has been tested with VC10 and compiled with g++ 4.5 (with and without -std=c++0x) and clang++ (without c++0x).

Change History (2)

by nathan.crookston+boost@…, 10 years ago

Attachment: range.diff added

patch for proposed syntax

comment:1 by viboes, 9 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.