aboutsummaryrefslogtreecommitdiff
path: root/pages/projects/const_list.md
blob: 9a5c18c6f41e310d95390215c725e97f52904d45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# ConstList

…is a experimental compile-time functional-style list library written in C++.

The MIT licensed implementation may be found on [Github] or [cgit].

It was written as a experiment in how far one could take the optional compile-time executability offered by `constexpr` specifically and the C++ template metaprogramming facilities in general. While basic _Cons_ structures and appropriate accessor functions turned out to be quite straight forward to implement, the current problem is the absence of workable arbitrary value comparison in a templated context if one doesn't want to be limited to values that can be used as template parameters such as integers. This means that it is currently impossible to e.g. filter a list using `foldr`.

Note that these restrictions were overcome in my [second attempt] at this problem which follows the concept of viewing types as values and templates as functions.

## Current features

- `Cons` class template for representing constant list structures at compile time
- `make` method template for easily constructing `Cons` structures
- list constructors such as `make` and `concatenate`
- basic list accessors such as `size`, `head`, `tail`, `nth` and `take`
- higher order list operators such as `foldr`, `foldl` and `map`
- higher order list queries such as `any`, `all`, `none` and `count`
- special purpose methods such as `reverse`
- test cases for all of the above
- MIT license

## Usage example

~~~
const int sum{
	ConstList::foldr(
		ConstList::make(1, 2, 3, 4, 5),
		[](const int& x, const int& y) {
			return x + y;
		},
		0
	)
}; // => 15
~~~
{: .language-cpp}

[Github]: https://github.com/KnairdA/ConstList/
[cgit]: http://code.kummerlaender.eu/ConstList/
[second attempt]: /page/type_as_value/