1 #ifndef SIPLASPLAS_CONSTEXPR_STRING_HPP 2 #define SIPLASPLAS_CONSTEXPR_STRING_HPP 4 #include "stringview.hpp" 5 #include "algorithm.hpp" 6 #include <siplasplas/utility/meta.hpp> 7 #include <siplasplas/utility/cast.hpp> 16 template<std::
size_t Size>
20 template<
typename Begin,
typename End>
21 constexpr
String(Begin begin, End end);
23 constexpr String(
const std::initializer_list<char>& initList);
25 template<std::
size_t StringSize>
26 constexpr String(
const char(&
string)[StringSize]);
28 constexpr
char operator[](std::size_t i)
const;
29 constexpr std::size_t size()
const;
31 constexpr
const char* begin()
const;
32 constexpr
const char* end()
const;
34 constexpr
ConstStringView operator()(std::size_t i, std::size_t j)
const;
36 std::string str()
const;
37 constexpr
const char* c_str()
const;
40 std::array<char, Size> _storage;
46 template<
typename Begin,
typename End, std::size_t... Is>
56 template<std::
size_t Size>
57 template<
typename Begin,
typename End>
59 _storage{detail::makeArray(begin, end, cpp::meta::make_index_sequence<Size>())}
62 template<std::
size_t Size>
63 constexpr String<Size>::String(
const std::initializer_list<char>& initList) :
64 String{initList.begin(), initList.end()}
67 template<std::
size_t Size>
68 template<std::
size_t StringSize>
69 constexpr String<Size>::String(
const char (&
string)[StringSize]) :
72 static_assert(Size >= StringSize,
"Not enough storage for the given string literal");
75 template<std::
size_t Size>
81 template<std::
size_t Size>
87 template<std::
size_t Size>
93 template<std::
size_t Size>
96 return &_storage[Size];
99 template<std::
size_t Size>
102 return { begin(), end() };
105 template<std::
size_t Size>
111 template<std::
size_t Size>
117 template<std::
size_t Size>
120 return view().c_str();
126 template<std::size_t LhsSize, std::size_t RhsSize, std::size_t... Is, std::size_t... Js>
139 template<std::
size_t LhsSize, std::
size_t RhsSize>
145 cpp::meta::make_index_sequence<LhsSize - 1>(),
146 cpp::meta::make_index_sequence<RhsSize>()
150 template<std::
size_t LhsSize, std::
size_t RhsSize>
159 template<std::
size_t LhsSize, std::
size_t RhsSize>
162 return !(lhs == rhs);
165 template<std::
size_t Size>
166 std::ostream& operator<<(std::ostream& os, const String<Size>& string)
168 return os <<
string.view();
171 template<std::
size_t N>
172 constexpr
String<N> stringLiteral(
const char (&stringLiteral)[N])
174 return {stringLiteral};
181 #endif // SIPLASPLAS_CONSTEXPR_STRING_HPP Definition: messaging.hpp:8
constexpr bool equal(Begin1 begin1, End1 end1, Begin2 begin2, End2 end2, Compare compare)
Compares if two sequences are equal.
Definition: algorithm.hpp:137
Definition: string.hpp:17
constexpr auto end(const Sequence &sequence)
Returns an iterator pointing to the end of a sequence.
Definition: algorithm.hpp:86
constexpr auto begin(const Sequence &sequence)
Returns an iterator pointing to the beginning of a sequence.
Definition: algorithm.hpp:62
Definition: test_util.hpp:13
Definition: stringview.hpp:63