Last active
August 18, 2017 14:08
-
-
Save Luiz-Monad/c300aa09e3667d26e40589184efb588f to your computer and use it in GitHub Desktop.
C++ helpers
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
class Random | |
{ | |
private: | |
function<int(void)> rnd; | |
public: | |
Random() { | |
auto rnde = default_random_engine(); | |
auto rndd = uniform_int_distribution<int>( | |
numeric_limits<char>::min(), | |
numeric_limits<char>::max()); | |
rnd = bind(rndd, rnde); | |
} | |
char operator () () { return rnd(); } | |
}; | |
struct Range | |
{ | |
//teach the STL how to use our iterator | |
typedef input_iterator_tag iterator_category; typedef long value_type; | |
typedef size_t size_type; typedef long difference_type; | |
typedef value_type* pointer; typedef value_type& reference; | |
private: | |
const long s; long i; const long e; | |
public: | |
Range(long s, long e) : s(s), i(s), e(e) {} | |
const Range & begin() const { return Range(s, e); } | |
const Range & end() const { return Range(e, e); } | |
const Range & operator ++ () { ++i; return *this; } | |
bool operator == (const Range & other) const { return i == other.i; } | |
bool operator != (const Range & other) const { return i != other.i; } | |
long operator * () const { return i; } | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment