An open API service indexing awesome lists of open source software.

https://github.com/avitase/static_rotation

C++ header-only library that uses TMP to generate all rotations of a given integral sequence at compile-time.
https://github.com/avitase/static_rotation

compile-time cpp cpp-library header-only rotations template-m tmp

Last synced: about 2 hours ago
JSON representation

C++ header-only library that uses TMP to generate all rotations of a given integral sequence at compile-time.

Awesome Lists containing this project

README

          

# `static_rotation`
`static_rotation` is a [header-only](static_rotation.hpp) library that uses template meta programming to generate all rotations of a given integer sequence at compile-time.

## Example
The snippet below generates all rotations of the sequence `(0,1,2,3)` and stores them in a `std::array`:
```
#include "static_rotation.hpp"
#include

int main() {
using namespace static_rotation;
using R = IndexRotations<4>;
constexpr auto values = R::values;

for (int i = 0; i < values.size(); i++) {
std::cout << values[i];
std::cout << (i % R::seq_length == R::seq_length - 1 ? '\n' : ' ');
}

}
```
The output of this snippet is
```
0 1 2 3
1 2 3 0
2 3 0 1
3 0 1 2
```
You can run the snippet on Compiler Explorer: [godbolt.org/z/uNmXFr](https://godbolt.org/z/uNmXFr)

`IndexRotations` generates the rotations for an index sequence `(0, 1, 2, ..., N)`. If the rotations for arbitrary sequences are needed, one may use `Rotations` directly, e.g.
```
Rotations;
```
see [godbolt.org/z/fWeikA](https://godbolt.org/z/fWeikA) for a complete example.
For more details take a look at [static_rotation.hpp](static_rotation.hpp).

## Installatation
This library is header-only and including [static_rotation.hpp](static_rotation.hpp) is sufficient.

## Requirements
The library uses `C++17` features. No external libraries are needed.