11
11
12
12
#include < __algorithm/copy_n.h>
13
13
#include < __algorithm/fill_n.h>
14
+ #include < __algorithm/find.h>
14
15
#include < __algorithm/find_end.h>
15
16
#include < __algorithm/find_first_of.h>
16
17
#include < __algorithm/min.h>
17
18
#include < __compare/ordering.h>
18
19
#include < __config>
19
20
#include < __functional/hash.h>
21
+ #include < __functional/identity.h>
20
22
#include < __iterator/iterator_traits.h>
21
23
#include < __string/constexpr_c_functions.h>
22
24
#include < __type_traits/is_constant_evaluated.h>
@@ -355,34 +357,35 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<char8_t>
355
357
{return __c1 < __c2;}
356
358
357
359
static _LIBCPP_HIDE_FROM_ABI constexpr int
358
- compare (const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
360
+ compare (const char_type* __s1, const char_type* __s2, size_t __n) noexcept {
359
361
return std::__constexpr_memcmp (__s1, __s2, __element_count (__n));
360
362
}
361
363
362
- static _LIBCPP_HIDE_FROM_ABI constexpr
363
- size_t length (const char_type* __s) _NOEXCEPT;
364
+ static _LIBCPP_HIDE_FROM_ABI constexpr size_t length (const char_type* __str) noexcept {
365
+ return std::__constexpr_strlen (__str);
366
+ }
364
367
365
- _LIBCPP_INLINE_VISIBILITY static constexpr
366
- const char_type* find (const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
368
+ static _LIBCPP_HIDE_FROM_ABI constexpr const char_type*
369
+ find (const char_type* __s, size_t __n, const char_type& __a) noexcept {
370
+ return std::__constexpr_memchr (__s, __a, __n);
371
+ }
367
372
368
- static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
369
- char_type* move (char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
370
- return std::__constexpr_memmove (__s1, __s2, __element_count (__n));
371
- }
373
+ static _LIBCPP_HIDE_FROM_ABI constexpr char_type*
374
+ move (char_type* __s1, const char_type* __s2, size_t __n) noexcept {
375
+ return std::__constexpr_memmove (__s1, __s2, __element_count (__n));
376
+ }
372
377
373
- static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
374
- char_type* copy (char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
375
- _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES (!std::__is_pointer_in_range (__s1, __s1 + __n, __s2),
376
- " char_traits::copy: source and destination ranges overlap" );
377
- std::copy_n (__s2, __n, __s1);
378
- return __s1;
379
- }
378
+ static _LIBCPP_HIDE_FROM_ABI constexpr char_type* copy (char_type* __s1, const char_type* __s2, size_t __n) noexcept {
379
+ _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES (!std::__is_pointer_in_range (__s1, __s1 + __n, __s2),
380
+ " char_traits::copy: source and destination ranges overlap" );
381
+ std::copy_n (__s2, __n, __s1);
382
+ return __s1;
383
+ }
380
384
381
- static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
382
- char_type* assign (char_type* __s, size_t __n, char_type __a) _NOEXCEPT {
383
- std::fill_n (__s, __n, __a);
384
- return __s;
385
- }
385
+ static _LIBCPP_HIDE_FROM_ABI constexpr char_type* assign (char_type* __s, size_t __n, char_type __a) noexcept {
386
+ std::fill_n (__s, __n, __a);
387
+ return __s;
388
+ }
386
389
387
390
static inline _LIBCPP_HIDE_FROM_ABI constexpr int_type not_eof (int_type __c) noexcept
388
391
{return eq_int_type (__c, eof ()) ? ~eof () : __c;}
@@ -396,31 +399,6 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<char8_t>
396
399
{return int_type (EOF);}
397
400
};
398
401
399
- // TODO use '__builtin_strlen' if it ever supports char8_t ??
400
- inline constexpr
401
- size_t
402
- char_traits<char8_t >::length(const char_type* __s) _NOEXCEPT
403
- {
404
- size_t __len = 0 ;
405
- for (; !eq (*__s, char_type (0 )); ++__s)
406
- ++__len;
407
- return __len;
408
- }
409
-
410
- // TODO use '__builtin_char_memchr' if it ever supports char8_t ??
411
- inline constexpr
412
- const char8_t *
413
- char_traits<char8_t >::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
414
- {
415
- for (; __n; --__n)
416
- {
417
- if (eq (*__s, __a))
418
- return __s;
419
- ++__s;
420
- }
421
- return nullptr ;
422
- }
423
-
424
402
#endif // _LIBCPP_HAS_NO_CHAR8_T
425
403
426
404
template <>
@@ -446,8 +424,15 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<char16_t>
446
424
int compare (const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
447
425
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_SINCE_CXX17
448
426
size_t length (const char_type* __s) _NOEXCEPT;
449
- _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_SINCE_CXX17
450
- const char_type* find (const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
427
+
428
+ static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const char_type*
429
+ find (const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT {
430
+ __identity __proj;
431
+ const char_type* __match = std::__find_impl (__s, __s + __n, __a, __proj);
432
+ if (__match == __s + __n)
433
+ return nullptr ;
434
+ return __match;
435
+ }
451
436
452
437
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
453
438
static char_type* move (char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
@@ -504,19 +489,6 @@ char_traits<char16_t>::length(const char_type* __s) _NOEXCEPT
504
489
return __len;
505
490
}
506
491
507
- inline _LIBCPP_CONSTEXPR_SINCE_CXX17
508
- const char16_t *
509
- char_traits<char16_t >::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
510
- {
511
- for (; __n; --__n)
512
- {
513
- if (eq (*__s, __a))
514
- return __s;
515
- ++__s;
516
- }
517
- return nullptr ;
518
- }
519
-
520
492
template <>
521
493
struct _LIBCPP_TEMPLATE_VIS char_traits<char32_t >
522
494
{
@@ -540,8 +512,15 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<char32_t>
540
512
int compare (const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
541
513
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_SINCE_CXX17
542
514
size_t length (const char_type* __s) _NOEXCEPT;
543
- _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_SINCE_CXX17
544
- const char_type* find (const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
515
+
516
+ static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const char_type*
517
+ find (const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT {
518
+ __identity __proj;
519
+ const char_type* __match = std::__find_impl (__s, __s + __n, __a, __proj);
520
+ if (__match == __s + __n)
521
+ return nullptr ;
522
+ return __match;
523
+ }
545
524
546
525
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
547
526
static char_type* move (char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
@@ -596,19 +575,6 @@ char_traits<char32_t>::length(const char_type* __s) _NOEXCEPT
596
575
return __len;
597
576
}
598
577
599
- inline _LIBCPP_CONSTEXPR_SINCE_CXX17
600
- const char32_t *
601
- char_traits<char32_t >::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
602
- {
603
- for (; __n; --__n)
604
- {
605
- if (eq (*__s, __a))
606
- return __s;
607
- ++__s;
608
- }
609
- return nullptr ;
610
- }
611
-
612
578
// helper fns for basic_string and string_view
613
579
614
580
// __str_find
0 commit comments