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.
- Host: GitHub
- URL: https://github.com/avitase/static_rotation
- Owner: avitase
- License: apache-2.0
- Created: 2019-12-14T16:03:00.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-12T14:13:40.000Z (over 6 years ago)
- Last Synced: 2026-03-31T21:29:41.096Z (3 months ago)
- Topics: compile-time, cpp, cpp-library, header-only, rotations, template-m, tmp
- Language: C++
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.