Boost logo

Boost Users :

Subject: Re: [Boost-users] [context] boost::coroutines::asymmetric_coroutine<T>::pull_type iterator does not properly model InputIterator
From: Mueller-Roemer, Johannes Sebastian (Johannes.Sebastian.Mueller-Roemer_at_[hidden])
Date: 2015-02-16 07:46:50


Compiling is not the issue. Furthermore your example does not test the issue I mentioned, as it does not use *it++;

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

From: Boost-users [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Oliver Kowalke
Sent: Monday, February 16, 2015 13:35
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] [context] boost::coroutines::asymmetric_coroutine<T>::pull_type iterator does not properly model InputIterator

#include <iostream>
#include <iterator>
#include <string>
#include <utility>

#include <boost/coroutine/all.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>

template<typename Continuation>
void bar(Continuation && yield) {
      yield("Hello");
      yield(", ");
      yield("World");
      yield("!\n");
}

using T = std::string;
using coro_t = boost::coroutines::asymmetric_coroutine<T>;

coro_t::pull_type foo() {
      return coro_t::pull_type{
            [](coro_t::push_type& yield) {
                bar(std::forward<coro_t::push_type>(yield));
            }};
}

int main(int, char **) {
      auto f = foo();

      for ( auto i = boost::begin( f); i != boost::end( f); ++i) {
          std::cout << * i << std::endl;
      }

      return 0;
}
compiles with master branch

2015-02-16 9:22 GMT+01:00 Mueller-Roemer, Johannes Sebastian <Johannes.Sebastian.Mueller-Roemer_at_[hidden]<mailto:Johannes.Sebastian.Mueller-Roemer_at_[hidden]>>:
I’m currently on Boost 1.56 so this might have been fixed by now, but in a simple test Boost.Coroutine fails to properly model the InputIterator concept, because *it++ does not conform to the operational semantics { T tmp = *it; ++it; return tmp; } required by the standard.

The failing program:

#include <boost/coroutine/asymmetric_coroutine.hpp>
#include <iostream>

template<typename Continuation>
auto foo(Continuation && yield) -> void
{
      yield("Hello");
      yield(", ");
      yield("World");
      yield("!\n");
}

//using T = char const *;
using T = std::string;

auto foo() -> boost::coroutines::asymmetric_coroutine<T>::pull_type
{
      using namespace boost::coroutines;
      return asymmetric_coroutine<T>::pull_type{
            [](asymmetric_coroutine<T>::push_type& yield) { foo(yield); }
      };
}

auto main(int, char **) -> int
{
      auto f = foo();
      for(auto it = boost::begin(f); it != boost::end(f);)
            std::cout << *it++;
}

Which (on my machine) outputs:
, World!
X☺à r2 ` , ` , Ç2 Ç

Failing to model the InputIterator concept is bad, because then it isn’t any kind of standards-conforming iterator at all. Interestingly, if T is char const * and not std::string the program works as expected. Is there some other subtle bug at work here?

--
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<tel:%2B49%206151%20155-606> | Fax +49 6151 155-139<tel:%2B49%206151%20155-139>
johannes.mueller-roemer_at_[hidden]<mailto:johannes.mueller-roemer_at_[hidden]> | www.igd.fraunhofer.de<http://www.igd.fraunhofer.de>


_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]<mailto: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