@@ -239,6 +239,7 @@ Software.
239
239
#include <utility>
240
240
#include <cstddef>
241
241
#include <string_view>
242
+ #include <array>
242
243
#include <cstdint>
243
244
244
245
namespace ctll {
@@ -271,11 +272,16 @@ constexpr length_value_t length_and_value_of_utf16_code_point(uint16_t first_uni
271
272
else return {first_unit, 1};
272
273
}
273
274
275
+ struct construct_from_pointer_t { };
276
+
277
+ constexpr auto construct_from_pointer = construct_from_pointer_t{};
278
+
274
279
template <size_t N> struct fixed_string {
275
280
char32_t content[N] = {};
276
281
size_t real_size{0};
277
282
bool correct_flag{true};
278
- template <typename T> constexpr fixed_string(const T (&input)[N+1]) noexcept {
283
+
284
+ template <typename T> constexpr fixed_string(construct_from_pointer_t, const T * input) noexcept {
279
285
if constexpr (std::is_same_v<T, char>) {
280
286
#ifdef CTRE_STRING_IS_UTF8
281
287
size_t out{0};
@@ -373,6 +379,10 @@ template <size_t N> struct fixed_string {
373
379
}
374
380
}
375
381
}
382
+
383
+ template <typename T> constexpr fixed_string(const std::array<T, N> & in) noexcept: fixed_string{construct_from_pointer, in.data()} { }
384
+ template <typename T> constexpr fixed_string(const T (&input)[N+1]) noexcept: fixed_string{construct_from_pointer, input} { }
385
+
376
386
constexpr fixed_string(const fixed_string & other) noexcept {
377
387
for (size_t i{0}; i < N; ++i) {
378
388
content[i] = other.content[i];
@@ -440,6 +450,8 @@ template <> class fixed_string<0> {
440
450
};
441
451
442
452
template <typename CharT, size_t N> fixed_string(const CharT (&)[N]) -> fixed_string<N-1>;
453
+ template <typename CharT, size_t N> fixed_string(const std::array<CharT,N> &) -> fixed_string<N>;
454
+
443
455
template <size_t N> fixed_string(fixed_string<N>) -> fixed_string<N>;
444
456
445
457
}
@@ -3051,7 +3063,7 @@ struct utf8_iterator {
3051
3063
3052
3064
struct sentinel {
3053
3065
// this is here only because I want to support std::make_reverse_iterator
3054
- using self_type = utf8_iterator ;
3066
+ using self_type = sentinel ;
3055
3067
using value_type = char8_t;
3056
3068
using reference = char8_t &;
3057
3069
using pointer = const char8_t *;
@@ -3069,6 +3081,20 @@ struct utf8_iterator {
3069
3081
friend constexpr auto operator==(self_type, const char8_t * other_ptr) noexcept {
3070
3082
return *other_ptr == char8_t{0};
3071
3083
}
3084
+
3085
+ friend constexpr auto operator!=(self_type, const char8_t * other_ptr) noexcept {
3086
+ return *other_ptr != char8_t{0};
3087
+ }
3088
+
3089
+ #if __cpp_impl_three_way_comparison < 201907L
3090
+ friend constexpr auto operator==(const char8_t * other_ptr, self_type) noexcept {
3091
+ return *other_ptr == char8_t{0};
3092
+ }
3093
+
3094
+ friend constexpr auto operator!=(const char8_t * other_ptr, self_type) noexcept {
3095
+ return *other_ptr != char8_t{0};
3096
+ }
3097
+ #endif
3072
3098
};
3073
3099
3074
3100
const char8_t * ptr{nullptr};
@@ -3078,8 +3104,8 @@ struct utf8_iterator {
3078
3104
return lhs.ptr < lhs.end;
3079
3105
}
3080
3106
3081
- constexpr friend bool operator!=(sentinel, const utf8_iterator & rhs) {
3082
- return rhs .ptr < rhs.end ;
3107
+ constexpr friend bool operator!=(const utf8_iterator & lhs, const char8_t * rhs) {
3108
+ return lhs .ptr != rhs;
3083
3109
}
3084
3110
3085
3111
constexpr friend bool operator!=(const utf8_iterator & lhs, const utf8_iterator & rhs) {
@@ -3090,10 +3116,33 @@ struct utf8_iterator {
3090
3116
return lhs.ptr >= lhs.end;
3091
3117
}
3092
3118
3119
+ constexpr friend bool operator==(const utf8_iterator & lhs, const char8_t * rhs) {
3120
+ return lhs.ptr == rhs;
3121
+ }
3122
+
3123
+ constexpr friend bool operator==(const utf8_iterator & lhs, const utf8_iterator & rhs) {
3124
+ return lhs.ptr == rhs.ptr;
3125
+ }
3126
+
3127
+ #if __cpp_impl_three_way_comparison < 201907L
3128
+ constexpr friend bool operator!=(sentinel, const utf8_iterator & rhs) {
3129
+ return rhs.ptr < rhs.end;
3130
+ }
3131
+
3132
+ constexpr friend bool operator!=(const char8_t * lhs, const utf8_iterator & rhs) {
3133
+ return lhs == rhs.ptr;
3134
+ }
3135
+
3093
3136
constexpr friend bool operator==(sentinel, const utf8_iterator & rhs) {
3094
3137
return rhs.ptr >= rhs.end;
3095
3138
}
3096
3139
3140
+ constexpr friend bool operator==(const char8_t * lhs, const utf8_iterator & rhs) {
3141
+ return lhs == rhs.ptr;
3142
+ }
3143
+ #endif
3144
+
3145
+
3097
3146
constexpr utf8_iterator & operator=(const char8_t * rhs) {
3098
3147
ptr = rhs;
3099
3148
return *this;
@@ -3874,6 +3923,12 @@ constexpr auto first(ctll::list<Content...> l, ctll::list<sequence<Seq...>, Tail
3874
3923
return first(l, ctll::list<Seq..., Tail...>{});
3875
3924
}
3876
3925
3926
+ // atomic group
3927
+ template <typename... Content, typename... Seq, typename... Tail>
3928
+ constexpr auto first(ctll::list<Content...> l, ctll::list<atomic_group<Seq...>, Tail...>) noexcept {
3929
+ return first(l, ctll::list<Seq..., Tail...>{});
3930
+ }
3931
+
3877
3932
// plus
3878
3933
template <typename... Content, typename... Seq, typename... Tail>
3879
3934
constexpr auto first(ctll::list<Content...> l, ctll::list<plus<Seq...>, Tail...>) noexcept {
@@ -4858,6 +4913,19 @@ constexpr CTRE_FORCE_INLINE R evaluate(const BeginIterator begin, Iterator curre
4858
4913
}
4859
4914
}
4860
4915
4916
+ template <typename...> constexpr auto dependent_false = false;
4917
+
4918
+ // atomic (unsupported for now)
4919
+ template <typename R, typename BeginIterator, typename Iterator, typename EndIterator, typename... Content, typename... Tail>
4920
+ constexpr CTRE_FORCE_INLINE R evaluate(const BeginIterator begin, Iterator current, const EndIterator last, const flags & f, R captures, ctll::list<atomic_group<Content...>, Tail...>) noexcept {
4921
+ (void)begin;
4922
+ (void)current;
4923
+ (void)last;
4924
+ (void)f;
4925
+ (void)captures;
4926
+ static_assert(dependent_false<Content...>, "Atomic groups are not supported (yet)");
4927
+ }
4928
+
4861
4929
// switching modes
4862
4930
template <typename R, typename BeginIterator, typename Iterator, typename EndIterator, typename Mode, typename... Tail>
4863
4931
constexpr CTRE_FORCE_INLINE R evaluate(const BeginIterator begin, Iterator current, const EndIterator last, const flags & f, R captures, ctll::list<mode_switch<Mode>, Tail...>) noexcept {
0 commit comments