Opened 10 years ago

Closed 9 years ago

#7748 closed Feature Requests (invalid)

Allow explicit result_type specification for transformed

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).

Attachments (1)

range.diff (6.4 KB ) - added by nathan.crookston+boost@… 10 years ago.
patch for proposed syntax

Download all attachments as: .zip

Change History (5)

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)

comment:2 by viboes, 9 years ago

Have you tried defining BOOST_RESULT_OF_USE_DECLTYPE? This is a know limitation (due to backward compatibility) of result-of.

comment:3 by Nathan Crookston <nathan.crookston+boost@…>, 9 years ago

BOOST_RESULT_OF_USE_DECLTYPE would be inappropriate in situations where a lacking decltype would cause problems with other libraries (e.g., proto).

But since I wrote this ticket, my patch to add a BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK (or similar) was more-or-less accepted. So this ticket should be closed as OBE (or whatever resolutions this trac instance has).

Thanks for reminding me of this ticket.

comment:4 by Neil Groves, 9 years ago

Resolution: invalid
Status: newclosed

The original request was valid. It is no longer valid to make a change to Boost.Range for this issue due to the other fix mentioned above.

Note: See TracTickets for help on using tickets.