Re: [Boost-bugs] [Boost C++ Libraries] #4189: Add better support for non-default constructible function objects

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #4189: Add better support for non-default constructible function objects
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-08-13 10:38:32


#4189: Add better support for non-default constructible function objects
-------------------------------+--------------------------------
  Reporter: djwalker | Owner: jeffrey.hellrung
      Type: Feature Requests | Status: new
 Milestone: Boost 1.43.0 | Component: iterator
   Version: Boost 1.42.0 | Severity: Problem
Resolution: | Keywords: transform_iterator
-------------------------------+--------------------------------

Comment (by Taras Kozlov):

 I`ve suffered from the same problem, when I tried to use it with lambdas.
 If lambda has non-empty capture list, it doesn`t provide constructor with
 zero arguments.

 {{{
 typedef boost::any_range<int, boost::random_access_traversal_tag, int,
 ptrdiff_t> int_range;


 int_range f(const vector<double>& v)
 {
     vector<double> vec;
     string str = "Hello";

     return vec | boost::adaptors::transformed([str](double v) -> int {
 return (int)v; });
 }

 }}}

 If boost::optional overhead is inacceptable, we may try to use aligned
 storage + placement new instead.

 I also want to notice simple workaround: assigning lambda to std::function
 will make it work


 {{{
 std::function<int(double)> lambda = [str](double v) -> int { return
 (int)v; };
 return vec | transformed(lambda);
 }}}

 This is not the perfect solution since it involves runtime overhead
 especially on large data ranges.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/4189#comment:4>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:13 UTC