Opened 15 years ago

Closed 12 years ago

#1427 closed Feature Requests (fixed)

[iterator] transform_iterator should use boost::result_of to determine functor result type

Reported by: anonymous Owned by: Dave Abrahams
Milestone: To Be Determined Component: iterator
Version: Boost 1.34.1 Severity: Problem
Keywords: transform_iterator result_of Cc:

Description

transform_iterator should use boost::result_of to determine result type of functor instead of nested result_type.

Attachments (4)

patch_transform_iterator (2.0 KB ) - added by debionne@… 13 years ago.
transform_iterator.hpp patch for boost 1.39
patch_transform_iterator_test (1.5 KB ) - added by debionne@… 13 years ago.
transform_iterator_test.cpp patch for boost 1.39
transform_iterator.patch (770 bytes ) - added by mimomorin@… 12 years ago.
A patch against trunk (boost/iterator/transform_iterator.hpp)
transform_iterator_test.patch (816 bytes ) - added by mimomorin@… 12 years ago.
A patch against trunk (libs/iterator/test/transform_iterator_test.cpp)

Download all attachments as: .zip

Change History (15)

by debionne@…, 13 years ago

Attachment: patch_transform_iterator added

transform_iterator.hpp patch for boost 1.39

by debionne@…, 13 years ago

transform_iterator_test.cpp patch for boost 1.39

comment:1 by debionne@…, 13 years ago

The patchs above changes the mechanism that computes the default result type of the given UnaryFunction to use boost::result_of. Consequently, transform_iterator now support polymorphic object function (i.e. function wich result type depends on the arguments type). Such a function object must implement the result_of 'protocol', that is implement a nested result structure such as :

template <class FArgs> struct result; template <class F, class T> struct result<F(T)> {typedef whatever<T>::type type};

A polymorphic object function is added to the tests.

comment:2 by Jeremiah Willcock, 12 years ago

Resolution: fixed
Status: newclosed

(In [62625]) Applied patches from #1427; fixes #1427

comment:3 by mimomorin@…, 12 years ago

Resolution: fixed
Status: closedreopened

Reopened, until merged to release.

comment:4 by Marshall Clow, 12 years ago

(In [67792]) Merging fixes to release; fixes #2294 fixes #4918 fixes #3645 refs #2823 refs #1427 refs #2893

comment:5 by Marshall Clow, 12 years ago

Resolution: fixed
Status: reopenedclosed

comment:6 by mimomorin@…, 12 years ago

Resolution: fixed
Status: closedreopened

r67792 does not seem to do anything with transform_iterator.hpp. Is there something missing?

comment:7 by Marshall Clow, 12 years ago

Resolution: fixed
Status: reopenedclosed

(In [68076]) Merging fixes to release; Fixes #1427

comment:8 by mimomorin@…, 12 years ago

Resolution: fixed
Status: closedreopened

I've experimented with the updated transform_iterator, and found a discrepancy between code and document.

The document says that the (default) reference member of transform_iterator is

result_of<UnaryFunction(iterator_traits<Iterator>::reference)>::type

But the code uses

result_of<UnaryFunction(iterator_traits<Iterator>::value_type)>::type

We should modify the code to use reference instead of value_type, because

  • the discrepancy is confusing for users
  • reference better interacts with the result_of protocol than value_type

The current code in trunk/release causes compiler error in the following code:

#include <boost/array.hpp>
#include <boost/iterator/transform_iterator.hpp>
#include <boost/spirit/include/phoenix.hpp>

int main(int argc, char* argv[])
{
    boost::array<int, 3> ar = {{}};
    
    *boost::make_transform_iterator(ar.cbegin(), boost::phoenix::arg_names::_1);
    
    return 0;
}

I will attach a patch for fixing this.

Sorry for reopening this ticket repeatedly.

by mimomorin@…, 12 years ago

Attachment: transform_iterator.patch added

A patch against trunk (boost/iterator/transform_iterator.hpp)

by mimomorin@…, 12 years ago

A patch against trunk (libs/iterator/test/transform_iterator_test.cpp)

comment:9 by Marshall Clow, 12 years ago

I've committed these patches as [68205]

comment:10 by Daniel James, 12 years ago

(In [68524]) Revert [68076], refs #1427.

Will try to fix this properly in 1.47.

comment:11 by Daniel James, 12 years ago

Resolution: fixed
Status: reopenedclosed

(In [70715]) Iterator: Use boost::result_of to determine nested result type of function in transform_iterator. Fixes #1427.

Note: See TracTickets for help on using tickets.