https://github.com/deepgrace/monster
  
  
    The Art of Template MetaProgramming (TMP) in Modern C++♦️ 
    https://github.com/deepgrace/monster
  
advanced algorithm c-plus-plus concept concepts cpp20 header-only metaprogram metaprogramming modern monster range search sequence sort template template-metaprogramming tmp tuple type-traits
        Last synced: 6 months ago 
        JSON representation
    
The Art of Template MetaProgramming (TMP) in Modern C++♦️
- Host: GitHub
- URL: https://github.com/deepgrace/monster
- Owner: deepgrace
- License: bsl-1.0
- Created: 2017-08-15T03:06:51.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-06-06T12:37:54.000Z (over 1 year ago)
- Last Synced: 2024-08-04T02:09:37.563Z (about 1 year ago)
- Topics: advanced, algorithm, c-plus-plus, concept, concepts, cpp20, header-only, metaprogram, metaprogramming, modern, monster, range, search, sequence, sort, template, template-metaprogramming, tmp, tuple, type-traits
- Language: C++
- Homepage: https://deepgrace.github.io/monster
- Size: 1000 KB
- Stars: 154
- Watchers: 9
- Forks: 15
- Open Issues: 0
- 
            Metadata Files:
            - Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE_1_0.txt
 
Awesome Lists containing this project
- AwesomeCppGameDev - monster
README
          # Monster [](https://github.com/deepgrace/monster/blob/master/LICENSE_1_0.txt) [](https://github.com/deepgrace/monster/blob/master/Guidelines.md) [](https://en.cppreference.com/w/cpp/compiler_support) [](https://github.com/deepgrace/monster) [](https://gitter.im/taotmp/monster)
> **Advanced C++ Template MetaProgramming Framework**
## Overview
```cpp
#include 
#include 
using namespace monster;
int main(int argc, char* argv[])
{
    // arrange the same elements adjacent in a sequence, keep the relative order
    using a1 = adjacent_t>;
    using a2 = adjacent_t>;
    static_assert(std::is_same_v>);
    static_assert(std::is_same_v>);
    // Boyer-Moore-Horspool (BMH) algorithm searches for occurrences of a sequence within another sequence
    using b1 = bmh_t, std::tuple>;
    using b2 = bmh_t, std::integer_sequence>;
    static_assert(std::is_same_v>);
    static_assert(std::is_same_v>);
    // Knuth–Morris–Pratt (KMP) algorithm searches for occurrences of a sequence within another sequence
    using k1 = kmp_t, std::tuple>;
    using k2 = kmp_t, std::integer_sequence>;
    static_assert(std::is_same_v>);
    static_assert(std::is_same_v>);
    // find K-th smallest element in a sequence (k == 2)
    using min1 = select_t<2, std::tuple>;
    using min2 = select_t<2, std::integer_sequence>;
    static_assert(std::is_same_v);
    static_assert(std::is_same_v>);
    // find K-th greatest element in a sequence (k == 2)
    using max1 = select_t<2, std::tuple, greater_equal_t>;
    constexpr auto max2 = select_v<2, std::integer_sequence, greater_equal_t>;
    static_assert(std::is_same_v);
    static_assert(max2 == 3);
    // returns element at specific index of a sequence
    using e1 = element_t<1, std::tuple>;
    using e2 = element_t<3, std::integer_sequence>;
    constexpr auto e3 = element_v<3, std::integer_sequence>;
    static_assert(std::is_same_v);
    static_assert(std::is_same_v);
    static_assert(e3 == 4);
    // remove duplicate elements from a sequence, keep the first appearance
    using u1 = unique_t>;
    using u2 = unique_t>;
    static_assert(std::is_same_v>);
    static_assert(std::is_same_v>);
    // swap elements at specific index of a sequence
    using s1 = swap_t<1, 3, std::tuple>;
    using s2 = swap_t<0, 2, std::integer_sequence>;
    static_assert(std::is_same_v>);
    static_assert(std::is_same_v>);
    // sort elements by value in a sequence
    using s3 = quick_sort_t>;
    using s4 = quick_sort_t>;
    static_assert(std::is_same_v>);
    static_assert(std::is_same_v>);
    // sort elements by index in a sequence
    using s5 = sort_index_t>;
    using s6 = sort_index_t>;
    static_assert(std::is_same_v>);
    static_assert(std::is_same_v>);
    // reverses the order of the elements of a sequence
    using r1 = reverse_t>;
    using r2 = reverse_t>;
    static_assert(std::is_same_v>);
    static_assert(std::is_same_v>);
    // reverses the order of the elements of a sequence recursively
    using r3 = reverse_recursive_t>, char>>;
    using r4 = reverse_recursive_t, int>>;
    static_assert(std::is_same_v, int>, int>>);
    static_assert(std::is_same_v, char>>);
    // rotates the elements in the range [begin, middle, end) of a sequence
    using r5 = rotate_t<0, 2, 5, std::tuple>;
    using r6 = rotate_t<2, 4, 7, std::integer_sequence>;
    static_assert(std::is_same_v>);
    static_assert(std::is_same_v>);
    // returns the elements in the range [begin, end) of a sequence
    using r7 = range_t<1, 5, std::tuple>;
    using r8 = range_t<2, 6, std::integer_sequence>;
    static_assert(std::is_same_v>);
    static_assert(std::is_same_v>);
    return 0;
}
```
## Introduction
Monster is a metaprogramming library, which is header-only, extensible and modern C++ oriented.  
It exhibits a form of pure type programming of compile-time algorithms, sequences and Higher-Order Metafunctions.
Monster provides a conceptual foundation and an extensive set of powerful and coherent tools, that
makes doing explict advanced Template MetaProgramming (**TMP**) in modern C++ easy and enjoyable.
## Compiler requirements
The library relies on a C++20 compiler and standard library, but nothing else is required.
More specifically, Monster requires a compiler/standard library supporting the following C++20 features (non-exhaustively):
- concepts
- lambda templates
- All the C++20 type traits from the  header
## Building
Monster is header-only. To use it just add the necessary `#include` line to your source files, like this:
```cpp
#include 
```
To build the example with cmake, `cd` to the root of the project and setup the build directory:
```bash
mkdir build
cd build
cmake ..
```
Make and install the executables:
```
make -j4
make install
```
The executables are now located at the `bin` directory of the root of the project.  
The example can also be built with the script `build.sh`, just run it, the executables will be put at the `/tmp` directory.
## Documentation
You can browse the documentation online at [Guidelines.md](Guidelines.md).  
The documentation covers everything you should need including installing the library,
a table of contents, and an extensive reference section with examples.
## Full example
Please see [Tutorial.md](Tutorial.md).
## License
Monster is licensed as [Boost Software License 1.0](LICENSE_1_0.txt).