https://github.com/avakar/metapp
A small header-only C++ library for manipulating lists of types.
https://github.com/avakar/metapp
Last synced: about 2 months ago
JSON representation
A small header-only C++ library for manipulating lists of types.
- Host: GitHub
- URL: https://github.com/avakar/metapp
- Owner: avakar
- Created: 2017-05-22T16:47:31.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-05-22T18:10:17.000Z (about 8 years ago)
- Last Synced: 2025-04-12T19:57:45.577Z (about 2 months ago)
- Language: C++
- Homepage:
- Size: 5.86 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://travis-ci.org/avakar/metapp)
# Meta++
A small header-only C++ library for manipulating lists of types.
## Installation
Clone anywhere and make "include" directory visible. If you're using CMake, you can link against avakar_metapp target and the include directories will be made available automatically.
## Getting started
Lists of types are represented using `avakar::meta::list` template.
#include
namespace meta = avakar::meta;
using L = meta::list;Lists can be empty or contain repeated elements. Note that the `list` class is incomplete and cannot be instantiated. There is a collection of metafunctions one would expect to have to manipulate lists.
* `length`: returns `n`.
* `contains`: returns true if there is an `i` such that `T_i == T`.
* `contains_unique`: returns true if there is exactly one `i` such that `T_i == T`.
* `first_index_of`: returns the first `i` such that `T_i == T`. The class is incomplete if `!contains`.
* `index_of`: returns `i` such that `T_i == T`. Incomplete if `!contains_unique`.
* `sub`: returns `T_i`.
* `concat`: returns a concatenation of lists `L_i`. Arguments that are not `list` are wrapped in one; as such this metafunction also works as an append.## Choosing a type at runtime
The major reason for the library is the function `visit`, which accepts a list as a template argument, and an index and a visitor function as its regular arguments. Visit calls the visitor with an argument of type `list_item`.
void * storage = /*...*/;
using L = meta::list;
size_t index = 1;// prints the content of `storage` as if it contained a std::string
meta::visit(index, [storage](auto m) {
std::cout << *static_cast(storage) << "\n";
});