summaryrefslogtreecommitdiff
path: root/modules/core/string_literal.h
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2023-12-04 12:20:01 +0100
committerClaudius "keldu" Holeksa <mail@keldu.de>2023-12-04 12:20:01 +0100
commitfb7ed24d557c9f9ac5eaa60dbf22cba509953c1a (patch)
treefd9da3393972d07bef6aafaaafe7e3c7b27184e0 /modules/core/string_literal.h
parenta14896f9ed209dd3f9597722e5a5697bd7dbf531 (diff)
core: Moving structure around
Diffstat (limited to 'modules/core/string_literal.h')
-rw-r--r--modules/core/string_literal.h57
1 files changed, 0 insertions, 57 deletions
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 <array>
-#include <string_view>
-
-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 CharT, size_t N> 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<CharT, N> data{};
-
- constexpr std::string_view view() const noexcept {
- return std::string_view{data.data()};
- }
-
- constexpr bool
- operator==(const string_literal<CharT, N> &) const noexcept = default;
-
- template <class CharTR, size_t NR>
- constexpr bool
- operator==(const string_literal<CharTR, NR> &) const noexcept {
- return false;
- }
-
- template<size_t NR>
- constexpr string_literal<CharT, N+NR-1> operator+(const string_literal<CharT, NR>& 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<CharT, N+NR-1>{sum};
- }
-};
-
-template <typename T, T... Chars>
-constexpr string_literal<T, sizeof...(Chars) + 1u> operator""_sl() {
- return string_literal<T, sizeof...(Chars) + 1u>{{Chars..., '\0'}};
-}
-} // namespace saw