#7988 closed Bugs (fixed)
[Coroutine] Support for C++11 range-for is missing
Reported by: | ld | Owned by: | olli |
---|---|---|---|
Milestone: | To Be Determined | Component: | coroutine |
Version: | Boost 1.53.0 | Severity: | Problem |
Keywords: | Cc: |
Description
Using a snapshot of the upcoming GCC 4.8 release and Boost 1.53, the following does not compile:
#include <boost/coroutine/all.hpp> int main() { using coro = boost::coroutines::coroutine<int()>; for(int i: coro { [](coro::caller_type& yield) { yield(42); } }) { // unused static_cast<void>(i); } }
As far as I can tell, this is because while Boost.Coroutine does provide functionality for e.g. boost::begin(c) and boost::end(c), it does not provide for the similar, ADL-enabled uses like begin(c) and end(c), where begin and end are in scope.
As it so happens, boost::begin and boost::end do ADL on behalf of the users -- their Standard counterparts do not, and a range-for statement is specified to make use of unqualified calls to begin and end.
To substantiate my hypothesis, adding begin and end function templates in e.g. namespace boost::coroutines does appear to make the previous snippet compile, and more involved examples behave as expected.
// Try adding this: namespace boost { namespace coroutines { template<typename Sig> auto begin(coroutine<Sig>& c) -> decltype(boost::begin(c)) { return boost::begin(c); } template<typename Sig> auto end(coroutine<Sig>& c) -> decltype(boost::end(c)) { return boost::end(c); } } }
Change History (6)
comment:1 by , 10 years ago
Component: | None → coroutine |
---|---|
Owner: | set to |
comment:2 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:3 by , 9 years ago
follow-up: 6 comment:5 by , 8 years ago
The problem is in fact *not* fixed, see http://lists.boost.org/boost-users/2014/08/82815.php
comment:6 by , 8 years ago
Replying to anonymous:
The problem is in fact *not* fixed, see http://lists.boost.org/boost-users/2014/08/82815.php
example/cpp11/asymmetric/fibonacci compiles with gcc-4.8.1, clang-3.4.1, msvc-11 without problems
b2 toolset=gcc cxxflags="-std=c++11" b2 toolset=clang cxxflags="-std=c++11" b2 toolset=msvc-11
The range-for does not work with Clang 3.4, boost 1.55.0. The unidirectional coroutine example fails to compile, with the following message.
For now wrapping with boost::make_iterator_range(my_coro) will solve the problem, but a cleaner solution would be well appreciated.