diff --git a/include/pit/algorithms.h b/include/pit/algorithms.h new file mode 100644 index 0000000..6e1a747 --- /dev/null +++ b/include/pit/algorithms.h @@ -0,0 +1,85 @@ +#include +namespace pit{ + template + class lazy_transform{ + private: + std::function transformation; + InputIt start; + InputIt ending; + public: + class iterator{ + private: + InputIt underlying; + std::function transformation; + iterator(InputIt u,std::function transformation ):underlying(u), transformation(transformation){} + public: + iterator operator+(std::size_t amount){ + return iterator(this->underlying+amount); + } + void operator+=(std::size_t amount){ + this->underlying += amount; + } + iterator operator-(std::size_t amount){ + return iterator(this->underlying-amount); + } + void operator-=(std::size_t amount){ + this->underlying -= amount; + } + bool operator==(iterator const& rhs){ + return this->underlying == rhs.underlying; + } + OutputType operator*(){ + return transformation(*underlying); + } + }; + lazy_transform(InputIt start, InputIt end, std::function transformation):start(start), ending(end), transformation(transformation){} + iterator begin(){ + return iterator(start); + } + iterator end(){ + return iterator(ending); + } + }; + template + class lazy_filter{ + private: + std::function filter; + InputIt start; + InputIt ending; + public: + class iterator{ + private: + InputIt underlying; + InputIt ending; + std::function filter; + iterator(InputIt point, InputIt ending,std::function filter ):underlying(u), filter(filter){} + public: + iterator operator+(std::size_t amount){ + return iterator(this->underlying+amount); + } + void operator+=(std::size_t amount){ + this->underlying += amount; + + } + iterator operator-(std::size_t amount){ + return iterator(this->underlying-amount); + } + void operator-=(std::size_t amount){ + this->underlying -= amount; + } + bool operator==(iterator const& rhs){ + return this->underlying == rhs.underlying; + } + InputType operator*(){ + return *underlying; + } + }; + lazy_filter(InputIt start, InputIt end, std::function filter):start(start), ending(end), filter(filter){} + iterator begin(){ + return iterator(start); + } + iterator end(){ + return iterator(ending); + } + }; +} diff --git a/include/pit/iters.h b/include/pit/iters.h index e69de29..cf23dda 100644 --- a/include/pit/iters.h +++ b/include/pit/iters.h @@ -0,0 +1,57 @@ +#include +namespace pit{ + template + class passthrough{ + T underlying; + public: + passthrough(T underlying): underlying(underlying){} + passthrough(passthrough& from): underlying(from.underlying){} + passthrough operator+(std::size_t amount){ + return passthrough(this->underlying+amount); + } + void operator+=(std::size_t amount){ + this->underlying += amount; + } + passthrough operator-(std::size_t amount){ + return passthrough(this->underlying-amount); + } + void operator-=(std::size_t amount){ + this->underlying -= amount; + } + T const& operator*(){ + return this->underlying; + } + bool operator==(passthrough const& rhs){ + return this->underlying == rhs.underlying; + } + }; + template + class range{ + private: + T beginning; + T ending; + public: + range(T begin, T end):beginning(begin), ending(end){} + passthrough begin(){ + return passthrough(this->beginning); + } + passthrough end(){ + return passthrough(this->ending); + } + }; + + template + class repeat{ + T val; + public: + // noops + repeat operator+(std::size_t ){} + repeat operator-(std::size_t ){} + void operator+=(std::size_t ){} + void operator-=(std::size_t ){} + bool operator==(repeat const& rhs){return true;} + T const& operator*(){ + return this->val; + } + }; +} diff --git a/include/pit/manipulators.h b/include/pit/manipulators.h deleted file mode 100644 index e69de29..0000000