Skip to content

Instantly share code, notes, and snippets.

@nurettin
Created March 27, 2013 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nurettin/5253786 to your computer and use it in GitHub Desktop.
Save nurettin/5253786 to your computer and use it in GitHub Desktop.
play with boost range and overloading string operator
#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