2 ms·
You don't have to do this, here's an alternative approach: template<std::size_t N> struct fstr: public std::array<char, N + 1> { using std::array<char, N +
by cristeigabriel 3y ago
You don't have to do this, here's an alternative approach:
template<std::size_t N>
struct fstr: public std::array<char, N + 1> {
using std::array<char, N + 1>::array;
constexpr fstr(const char* str) noexcept : std::array<char, N + 1>() {
for (size_t i = 0; i < N; i++) (*this)[i] = str[i];
}
};
template<std::size_t N>
fstr(const char (&)[N]) noexcept -> fstr<N - 1>;
template <fstr sz>
struct log {
log() {
std::cout << std::string_view{ sz.data(), sz.size() } << std::endl;
}
};
int main() {
log<"Hello, world!"> _;
}