Created
March 27, 2013 12:22
-
-
Save nurettin/5253786 to your computer and use it in GitHub Desktop.
play with boost range and overloading string operator
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
#include <iostream> | |
#include <string> | |
#include <boost/range/counting_range.hpp> | |
typedef boost::iterator_range<boost::counting_iterator<int> > counting_range_int_t; | |
counting_range_int_t operator "" _ri(char const* wtf, std::size_t len) | |
{ | |
static std::istringstream parse; | |
parse.clear(); | |
parse.str(std::string(wtf, wtf+ len)); | |
int begin, end; | |
parse>> begin; | |
parse.ignore(1); | |
parse>> end; | |
auto range= boost::counting_range(begin, end); | |
return range; | |
} | |
std::ostream &operator<< (std::ostream &out, counting_range_int_t const &r) | |
{ | |
out<< '['; | |
std::for_each(r.begin(), r.end(), [](int i){ std::cout<< i<< ", "; }); | |
return out<< "\b\b]\n"; | |
} | |
int main() | |
{ | |
std::cout<< "1-10"_ri; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment