Boost logo

Boost Users :

Subject: [Boost-users] Limitations of BOOST_COROUTINES_V2 (pass by reference)
From: Mueller-Roemer, Johannes Sebastian (Johannes.Sebastian.Mueller-Roemer_at_[hidden])
Date: 2014-07-03 07:55:45


Hi,

aside from the fact that the new coroutines are - apparently intentionally - only unidirectional now (currently not much of an issue for me), I noticed that it is apparently no longer possible to yield values by reference as shown in the following example:

#include <fstream>
#include <string>
#include <iostream>
#include <boost/coroutine/all.hpp>

using type = std::string;
auto lines_from_file(char const * fname) -> boost::coroutines::coroutine<type>::pull_type
{
                using namespace boost::coroutines;
                return coroutine<type>::pull_type{
                               [fname](coroutine<type>::push_type& yield)
                               {
                                               std::string line;
                                               std::ifstream stream(fname);
                                               while(stream)
                                                               std::getline(stream, line), yield(line);
                               },
                               attributes(fpu_not_preserved)
                };
}

int main(int, char**)
{
                auto lines = lines_from_file("test.txt");
                unsigned count = 0;
                for(auto& line : lines)
                               std::cout << std::setw(4) << ++count << ": " << line << "\n";
}

If one changes type to std::string const & the example no longer compiles. If I use the old BOOST_COROUTINES_V1 API boost::coroutines::coroutine<std::string const &()> works just fine. Is this limitation also intentional (why?) or is this an unintentional regression?

Regards
Johannes S. Mueller-Roemer

--
Johannes S. Mueller-Roemer, MSc
Wiss. Mitarbeiter - Interactive Engineering Technologies (IET)
Fraunhofer-Institut für Graphische Datenverarbeitung IGD
Fraunhoferstr. 5  |  64283 Darmstadt  |  Germany
Tel +49 6151 155-606  |  Fax +49 6151 155-139
johannes.mueller-roemer_at_[hidden]  |  www.igd.fraunhofer.de


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net