Skip to content
/ tri-list Public

A lazy C++ container implementation with support for std::ranges

Notifications You must be signed in to change notification settings

eerio/tri-list

Repository files navigation

tri-list

This repository contains an implementation of a lazy C++ container, developed by me as part of a C++ programming course at the University of Warsaw (MIMUW). The project was supposed to test our functional template programming in C++. It uses C++ concepts heavily. It also features a custom implementation of a C++ iterator, information about which are not particularly easy to find online (i.e. what methods do a class have to implement to be an iterator). It can be used in C++ ranges and features a lazy function application to the container`s elements (see the last snippet below)

Please for example take a look at this implementation of function composition:

tri-list/tri_list.h

Lines 127 to 134 in 6a6adb1

template <typename T>
inline T identity(T x) { return x; }
static_assert(modifier<decltype(identity<int>), int>);
template <typename T, modifier<T> F, modifier<T> G>
inline auto compose(F f, G g) {
return [f, g](T t) mutable { return f(g(std::forward<T>(t))); };
}

Or at this implementation of element access (with lazy modifiers application) which is a part of the iterator interface required by the C++ standard:

tri-list/tri_list.h

Lines 80 to 85 in 6a6adb1

elt_t operator*() const {
return std::visit(
[this](auto x) -> elt_t { return tri_lst->apply_modifiers(x); },
*base
);
}

It was fun! I learned much about templates in C++ (and about myself while debugging ;))

About

A lazy C++ container implementation with support for std::ranges

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published