From fb7ed24d557c9f9ac5eaa60dbf22cba509953c1a Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Mon, 4 Dec 2023 12:20:01 +0100 Subject: core: Moving structure around --- modules/core/string_literal.h | 57 ------------------------------------------- 1 file changed, 57 deletions(-) delete mode 100644 modules/core/string_literal.h (limited to 'modules/core/string_literal.h') diff --git a/modules/core/string_literal.h b/modules/core/string_literal.h deleted file mode 100644 index ccc8f49..0000000 --- a/modules/core/string_literal.h +++ /dev/null @@ -1,57 +0,0 @@ -#pragma once - -#include -#include - -namespace saw { -/** - * Helper object which creates a templated string from the provided string - * literal. It guarantees compile time uniqueness and thus allows using strings - * in template parameters. - */ -template class string_literal { -public: - static_assert(N > 0, "string_literal needs a null terminator"); - - constexpr string_literal(const CharT (&input)[N]) noexcept { - for (size_t i = 0; i < N; ++i) { - data[i] = input[i]; - } - } - - std::array data{}; - - constexpr std::string_view view() const noexcept { - return std::string_view{data.data()}; - } - - constexpr bool - operator==(const string_literal &) const noexcept = default; - - template - constexpr bool - operator==(const string_literal &) const noexcept { - return false; - } - - template - constexpr string_literal operator+(const string_literal& rhs) const noexcept { - CharT sum[N+NR-1]; - - // The weird i+1 happens due to needing to skip the '\0' terminator - for(size_t i = 0; (i+1) < N; ++i){ - sum[i] = data[i]; - } - for(size_t i = 0; i < NR; ++i){ - sum[i+N-1] = rhs.data[i]; - } - - return string_literal{sum}; - } -}; - -template -constexpr string_literal operator""_sl() { - return string_literal{{Chars..., '\0'}}; -} -} // namespace saw -- cgit v1.2.3