Boost logo

Boost :

Subject: [boost] [range] treating N-ary function with N-1 default args as unary
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2012-06-30 00:07:20


Hi,

Some Boost.Range adaptors, such as 'transformed' or 'filtered', require
a unary function. The documentation does not formally define "unary
function", but it's pretty clear what it ought to be: a function (object)
that's callable with one argument.

Thus, to me, the following is a perfectly valid unary function:

int foo(int a, int b = 0);

as it is callable with one argument.

However, Boost.Range does not accept such a function as an argument to
'transformed' or 'filtered'. For example, the following code:

#include <boost/range/adaptor/transformed.hpp>

int foo(int a, int b = 0);

int main()
{
    int A[5];
    A | boost::adaptors::transformed(foo);
}

produces the following compiler errors (recent Boost trunk, with GCC 4.7):

In file included from boost/preprocessor/iteration/detail/iter/forward1.hpp:52:0,
                 from boost/utility/result_of.hpp:113,
                 from boost/iterator/transform_iterator.hpp:23,
                 from boost/range/adaptor/transformed.hpp:16,
                 from test.cpp:1:
boost/utility/detail/result_of_iterate.hpp: In instantiation of 'struct boost::detail::cpp0x_result_of_impl<int (* const(int&))(int, int)>':
boost/utility/detail/result_of_iterate.hpp:46:8:   required from 'struct boost::result_of<int (* const(int&))(int, int)>'
boost/mpl/eval_if.hpp:38:31:   required from 'struct boost::mpl::eval_if<boost::is_same<boost::use_default, boost::use_default>, boost::result_of<int (* const(int&))(int, int)>, boost::mpl::identity<boost::use_default> >'
boost/iterator/iterator_adaptor.hpp:160:12:   required from 'struct boost::detail::ia_dflt_help<boost::use_default, boost::result_of<int (* const(int&))(int, int)> >'
boost/iterator/transform_iterator.hpp:50:17:   required from 'struct boost::detail::transform_iterator_base<int (*)(int, int), int*, boost::use_default, boost::use_default>'
c++/4.7.0/bits/stl_iterator_base_types.h:143:1:   recursively required from 'constexpr const bool std::__has_iterator_category_helper<boost::transform_iterator<int (*)(int, int), int*, boost::use_default, boost::use_default> >::value'
c++/4.7.0/bits/stl_iterator_base_types.h:143:1:   required from 'struct std::__has_iterator_category<boost::transform_iterator<int (*)(int, int), int*, boost::use_default, boost::use_default> >'
c++/4.7.0/bits/stl_iterator_base_types.h:160:12:   required from 'struct std::iterator_traits<boost::transform_iterator<int (*)(int, int), int*, boost::use_default, boost::use_default> >'
boost/detail/iterator.hpp:81:8:   required from 'struct boost::detail::iterator_traits<boost::transform_iterator<int (*)(int, int), int*, boost::use_default, boost::use_default> >'
boost/iterator/iterator_traits.hpp:30:75:   required from 'struct boost::iterator_value<boost::transform_iterator<int (*)(int, int), int*, boost::use_default, boost::use_default> >'
boost/range/iterator_range_core.hpp:139:49:   required from 'class boost::iterator_range<boost::transform_iterator<int (*)(int, int), int*, boost::use_default, boost::use_default> >'
boost/range/adaptor/transformed.hpp:25:16:   required from 'struct boost::range_detail::transformed_range<int (*)(int, int), int [5]>'
test.cpp:8:41:   required from here
boost/utility/detail/result_of_iterate.hpp:69:5: error: too few arguments to function
In file included from boost/range/iterator_range_core.hpp:22:0,
                 from boost/range/iterator_range.hpp:13,
                 from boost/range/adaptor/transformed.hpp:15,
                 from test.cpp:1:
boost/iterator/iterator_traits.hpp: In instantiation of 'struct boost::iterator_value<boost::transform_iterator<int (*)(int, int), int*, boost::use_default, boost::use_default> >':
boost/range/iterator_range_core.hpp:139:49:   required from 'class boost::iterator_range<boost::transform_iterator<int (*)(int, int), int*, boost::use_default, boost::use_default> >'
boost/range/adaptor/transformed.hpp:25:16:   required from 'struct boost::range_detail::transformed_range<int (*)(int, int), int [5]>'
test.cpp:8:41:   required from here
boost/iterator/iterator_traits.hpp:30:75: error: no type named 'value_type' in 'struct boost::detail::iterator_traits<boost::transform_iterator<int (*)(int, int), int*, boost::use_default, boost::use_default> >'
boost/iterator/iterator_traits.hpp: In instantiation of 'struct boost::iterator_difference<boost::transform_iterator<int (*)(int, int), int*, boost::use_default, boost::use_default> >':
boost/range/iterator_range_core.hpp:143:54:   required from 'class boost::iterator_range<boost::transform_iterator<int (*)(int, int), int*, boost::use_default, boost::use_default> >'
boost/range/adaptor/transformed.hpp:25:16:   required from 'struct boost::range_detail::transformed_range<int (*)(int, int), int [5]>'
test.cpp:8:41:   required from here
boost/iterator/iterator_traits.hpp:49:80: error: no type named 'difference_type' in 'struct boost::detail::iterator_traits<boost::transform_iterator<int (*)(int, int), int*, boost::use_default, boost::use_default> >'
boost/iterator/iterator_traits.hpp: In instantiation of 'struct boost::iterator_reference<boost::transform_iterator<int (*)(int, int), int*, boost::use_default, boost::use_default> >':
boost/range/iterator_range_core.hpp:157:53:   required from 'class boost::iterator_range<boost::transform_iterator<int (*)(int, int), int*, boost::use_default, boost::use_default> >'
boost/range/adaptor/transformed.hpp:25:16:   required from 'struct boost::range_detail::transformed_range<int (*)(int, int), int [5]>'
test.cpp:8:41:   required from here
boost/iterator/iterator_traits.hpp:36:74: error: no type named 'reference' in 'struct boost::detail::iterator_traits<boost::transform_iterator<int (*)(int, int), int*, boost::use_default, boost::use_default> >'

Would it be possible to treat N-ary functions with N-1 default arguments
as unary?

Thanks,
Nate
                                               


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk