Last active
November 11, 2019 18:25
-
-
Save BreadFish64/5dcae1cdd295fb1c1d3ba8d6bb0eac8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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