Skip to content

Instantly share code, notes, and snippets.

@omegacoleman
Created October 30, 2020 01:08
Show Gist options
  • Save omegacoleman/674aaa583938a800e152423e355d3e2d to your computer and use it in GitHub Desktop.
Save omegacoleman/674aaa583938a800e152423e355d3e2d to your computer and use it in GitHub Desktop.
编译期重复给定字符串n遍
#include <iostream>
#include <memory>
template <unsigned int Times> struct __attribute__((__packed__)) bracks
{
char a = '{';
char b = '}';
bracks<Times - 1> next;
constexpr const char* get() const noexcept
{
return reinterpret_cast<const char *>(std::addressof(a));
}
};
template <> struct __attribute__((__packed__)) bracks<0> { char csend = '\0'; };
int main(void)
{
bracks<8> br;
const char * s{br.get()};
std::cout << std::string{s} << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment