Created
November 27, 2012 17:41
-
-
Save Ignition/4155787 to your computer and use it in GitHub Desktop.
Using Oliver Kowalke's coroutines headers which will soon be in Boost
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://gitorious.org/boost-dev/boost-dev, coroutine branch | |
//g++ -I path/to/boost-dev -std=c++11 code.cpp -static -L path/to/boost-dev/stage/lib/ -lboost_context | |
#include <boost/coroutine/all.hpp> | |
#include <boost/bind.hpp> | |
#include <boost/range.hpp> | |
#include <iostream> | |
#include <vector> | |
using namespace std; | |
using namespace boost; | |
template <typename T> | |
using coro_pairT_void = coroutines::coroutine<pair<T&,T&>(void)>; | |
template <typename T> | |
void combinations(typename coro_pairT_void<T>::caller_type & self, vector<T> & input ) { | |
for (auto it1 = input.begin(), itend = input.end(); it1 != itend; it1++) { | |
for (auto it2 = std::next(it1); it2 != itend; it2++) { | |
self(pair<T&, T&>(*it1,*it2)); | |
} | |
} | |
}; | |
int main( void ) { | |
vector<int> numbers{1,2,3,4,5,6}; | |
coro_pairT_void<int> func(bind(combinations<int>, _1, numbers)); | |
for (auto it(begin(func)), itend(end(func)); it != itend; ++it) { | |
cout << it->first << ',' << it->second << endl; | |
} | |
return 0; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment