|
Boost Users : |
Subject: Re: [Boost-users] Limitations of BOOST_COROUTINES_V2 (pass by reference)
From: Nat Goodspeed (nat_at_[hidden])
Date: 2014-07-03 20:20:44
On Thu, Jul 3, 2014 at 7:55 AM, Mueller-Roemer, Johannes Sebastian
<Johannes.Sebastian.Mueller-Roemer_at_[hidden]> wrote:
> aside from the fact that the new coroutines are â apparently intentionally â
> only unidirectional now (currently not much of an issue for me),
I'm really curious about any real use case that you, or anyone else,
might have for bidirectional data flow with a coroutine.
> I noticed
> that it is apparently no longer possible to yield values by reference as
> shown in the following example:
I must respectfully disagree. I have a working example program using
the new syntax that yields temporary values from a polymorphic class
hierarchy by const reference.
> 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.
Could it be that auto& isn't matching std::string const&? What if you
change auto& to std::string const &?
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