Skip to content

Instantly share code, notes, and snippets.

@jameskeane
Created July 6, 2011 07:54
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 jameskeane/1066778 to your computer and use it in GitHub Desktop.
Save jameskeane/1066778 to your computer and use it in GitHub Desktop.
C++0x Lazy list (simple)
#include <functional>
template<typename T>
class LazyList
{
public:
typedef std::function<T(unsigned int, LazyList<T>*)> Generator;
LazyList(Generator gen)
: m_gen(gen)
{
}
T operator [](unsigned int n)
{
return m_gen(n, this);
}
private:
Generator m_gen;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment