Skip to content

Instantly share code, notes, and snippets.

@BreadFish64
Last active November 11, 2019 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BreadFish64/5dcae1cdd295fb1c1d3ba8d6bb0eac8b to your computer and use it in GitHub Desktop.
Save BreadFish64/5dcae1cdd295fb1c1d3ba8d6bb0eac8b to your computer and use it in GitHub Desktop.
#include <algorithm>
#include <array>
#include <iostream>
#include <string>
#include <type_traits>
constexpr std::array<char, 27> ALPHABET = []() constexpr {
std::remove_const<decltype(ALPHABET)>::type data{};
data[0] = ' ';
for (auto i = 0; i < data.size() - 1; ++i)
data[i + 1] = 'A' + i;
return data;
}
();
template <std::size_t size>
class Msg {
std::array<decltype(ALPHABET)::const_iterator, size> text = []() constexpr {
decltype(text) data{};
std::fill(data.begin(), data.end(), ALPHABET.begin());
return data;
}
();
typename decltype(text)::iterator ptr = text.begin();
public:
Msg& operator++() {
++(*ptr);
return *this;
}
Msg& operator++(int) {
++ptr;
return *this;
}
operator std::string() {
std::string out;
out.reserve(size);
for (auto it : text)
out += *it;
return out;
}
};
int main() {
std::cout << static_cast<std::string>(
++++++++(++++++++++++++++++++++++(++++++++++++++++++++++++++++++++++++(
++++++++++++++++++++++++++++++(++++++++++++++++++++++++++++++++++++++++++++++(
++++++++++++++++++++++++++++++(++++++++++++++++++++++++(++++++++++++++++++++++++(
++++++++++(++++++++++++++++Msg<11>())++)++)++)++)++++)++)++)++)++);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment