Sorry for the misunderstanding, the part in the parentheses was meant to point out that I currently do not require bidirectional data flow, so I don't have a use case for that ;)
The auto& is not the issue and works just fine in the BOOST_COROUTINES_V1 case (and if it were, it would be a compiler bug as auto& must match std::string const &).
Here is the error message using auto& and type=std::string const &:
In file included from D:/libs/mingw-amd64/boost_1_55_0/include/boost/optional.hpp:15:0,
from D:/libs/mingw-amd64/boost_1_55_0/include/boost/coroutine/v2/coroutine.hpp:17,
from D:/libs/mingw-amd64/boost_1_55_0/include/boost/coroutine/coroutine.hpp:11,
from D:/libs/mingw-amd64/boost_1_55_0/include/boost/coroutine/all.hpp:11,
from D:\projects\coro\coro_getline.cpp:4:
D:/libs/mingw-amd64/boost_1_55_0/include/boost/optional/optional.hpp: In instantiation of 'void boost::optional_detail::optional_base<T>::assign(const boost::optional<U>&) [with U = const std::basic_string<char>&; T = const std::basic_string<char>*]':
D:/libs/mingw-amd64/boost_1_55_0/include/boost/optional/optional.hpp:588:9: required from 'boost::optional<T>& boost::optional<T>::operator=(const boost::optional<U>&) [with U = const std::basic_string<char>&; T = const std::basic_string<char>*]'
D:/libs/mingw-amd64/boost_1_55_0/include/boost/coroutine/v2/detail/pull_coroutine_base.hpp:227:17: required from 'void boost::coroutines::detail::pull_coroutine_base
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 mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users