Boost logo

Boost Users :

Subject: [Boost-users] [coroutine] help with code from docs
From: Jeff Flinn (jeffrey.flinn_at_[hidden])
Date: 2013-09-12 11:20:07


I'm trying to understand coroutine usage with boost 1.53.0. I'm getting
an assertion when running the code snippet from the docs "Creating a
coroutine" from
http://www.boost.org/doc/libs/1_53_0/libs/coroutine/doc/html/coroutine/coroutine.html

#include <boost/coroutine/all.hpp>

#include <string>

typedef boost::coroutines::coroutine< int (std::string const&) > coro_t;

// void f( boost::coroutine< std::string const&( int) > & ca)
void f( coro_t::caller_type & ca)
{
     std::string str( ca.get() ); // asserts here!

     ca(7);
}

int main(int argc, char* argv[])
{
     std::string str("abc");

     coro_t c(f);

     c(str); // pass argument

     int res = c.get(); // returned value

     return 0;
}

Asserts in coroutine_get.hpp line 43:

BOOST_ASSERT( static_cast< D const* >( this)->impl_->result_);

Is the snippet from the doc incorrect or am I doing something else wrong.

Thanks, Jeff


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