Boost logo

Boost Users :

Subject: Re: [Boost-users] Limitations of BOOST_COROUTINES_V2 (pass by reference)
From: Mueller-Roemer, Johannes Sebastian (Johannes.Sebastian.Mueller-Roemer_at_[hidden])
Date: 2014-07-04 02:28:11


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<R&>::pull() [with R = const std::basic_string<char>]'
D:/libs/mingw-amd64/boost_1_55_0/include/boost/coroutine/v2/coroutine.hpp:1592:9: required from 'boost::coroutines::pull_coroutine<R&>& boost::coroutines::pull_coroutine<R&>::operator()() [with R = const std::basic_string<char>]'
D:/libs/mingw-amd64/boost_1_55_0/include/boost/coroutine/v2/coroutine.hpp:1630:21: required from 'void boost::coroutines::pull_coroutine<R&>::iterator::increment_() [with R = const std::basic_string<char>]'
D:/libs/mingw-amd64/boost_1_55_0/include/boost/coroutine/v2/coroutine.hpp:1666:24: required from 'boost::coroutines::pull_coroutine<R&>::iterator& boost::coroutines::pull_coroutine<R&>::iterator::operator++() [with R = const std::basic_string<char>]'
D:\projects\coro\coro_getline.cpp:26:19: required from here
D:/libs/mingw-amd64/boost_1_55_0/include/boost/optional/optional.hpp:293:88: error: invalid static_cast from type 'boost::optional_detail::types_when_is_ref<const std::basic_string<char>&>::raw_type {aka const std::basic_string<char>}' to type 'boost::optional_detail::optional_base<const std::basic_string<char>*>::value_type {aka const std::basic_string<char>*}'
              assign_value(static_cast<value_type>(rhs.get()), is_reference_predicate() );
                                                                                        ^
D:/libs/mingw-amd64/boost_1_55_0/include/boost/optional/optional.hpp:299:55: error: invalid static_cast from type 'boost::optional_detail::types_when_is_ref<const std::basic_string<char>&>::raw_type {aka const std::basic_string<char>}' to type 'boost::optional_detail::optional_base<const std::basic_string<char>*>::value_type {aka const std::basic_string<char>*}'
           construct(static_cast<value_type>(rhs.get()));
                                                       ^

Using std::string const & instead of auto results in an *identical* error message. An old-style iterator-based for loop produces a nearly identical error. FIY the compiler is GCC 4.9.0 Mingw-w64 (which does have some other issues with boost.context, as the result of the ml64 output produces " corrupt .drectve at end of def file" warnings at link time, but that is unrelated to this issue).

--
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

-----Original Message-----
From: Boost-users [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Nat Goodspeed
Sent: Friday, July 04, 2014 02:21
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] Limitations of BOOST_COROUTINES_V2 (pass by reference)

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 mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


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