Skip to content

Commit 2d3bb27

Browse files
author
Hana Dusíková
committed
- removal of basic_fixed_string (it was unused)
- fixed_string calculate capacity without \0 at the end, so the result fixed_string is exactly same as the one build by id<...> - less template instantiations aroung result.get<...>() functions
1 parent 509b646 commit 2d3bb27

File tree

4 files changed

+408
-274
lines changed

4 files changed

+408
-274
lines changed

include/ctll/fixed_string.hpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ template <size_t N> struct fixed_string {
4141
size_t real_size{0};
4242
bool correct_flag{true};
4343

44-
template <typename T> constexpr fixed_string(const T (&input)[N]) noexcept {
44+
template <typename T> constexpr fixed_string(const T (&input)[N+1]) noexcept {
4545
if constexpr (std::is_same_v<T, char>) {
4646
#if CTRE_STRING_IS_UTF8
4747
size_t out{0};
@@ -168,10 +168,13 @@ template <size_t N> struct fixed_string {
168168
}
169169
return true;
170170
}
171+
constexpr operator std::basic_string_view<char32_t>() const noexcept {
172+
return std::basic_string_view<char32_t>{content, size()};
173+
}
171174
};
172175

173176
template <> class fixed_string<0> {
174-
static constexpr char32_t __empty[1] = {0};
177+
static constexpr char32_t empty[1] = {0};
175178
public:
176179
template <typename T> constexpr fixed_string(const T *) noexcept {
177180

@@ -189,29 +192,28 @@ template <> class fixed_string<0> {
189192
return 0;
190193
}
191194
constexpr const char32_t * begin() const noexcept {
192-
return __empty;
195+
return empty;
193196
}
194197
constexpr const char32_t * end() const noexcept {
195-
return __empty + size();
198+
return empty + size();
196199
}
197200
constexpr char32_t operator[](size_t) const noexcept {
198201
return 0;
199202
}
203+
constexpr operator std::basic_string_view<char32_t>() const noexcept {
204+
return std::basic_string_view<char32_t>{empty, 0};
205+
}
200206
};
201207

202-
template <typename CharT, size_t N> fixed_string(const CharT (&)[N]) -> fixed_string<N>;
208+
template <typename CharT, size_t N> fixed_string(const CharT (&)[N]) -> fixed_string<N-1>;
203209
template <size_t N> fixed_string(fixed_string<N>) -> fixed_string<N>;
204210

205-
template <typename T, size_t N> class basic_fixed_string: public fixed_string<N> {
206-
using parent = fixed_string<N>;
207-
public:
208-
template <typename... Args> constexpr basic_fixed_string(Args && ... args) noexcept: parent(std::forward<Args>(args)...) { }
209-
};
210-
211-
template <typename CharT, size_t N> basic_fixed_string(const CharT (&)[N]) -> basic_fixed_string<CharT, N>;
212-
template <typename CharT, size_t N> basic_fixed_string(basic_fixed_string<CharT, N>) -> basic_fixed_string<CharT, N>;
213-
214-
215211
}
216212

213+
#if (__cpp_nontype_template_parameter_class || (__cpp_nontype_template_args >= 201911L))
214+
#define CTLL_FIXED_STRING ctll::fixed_string
215+
#else
216+
#define CTLL_FIXED_STRING const auto &
217+
#endif
218+
217219
#endif

0 commit comments

Comments
 (0)