Skip to content

Commit 4993f5b

Browse files
authored
[libc++][NFC] Use variable templates in <string> (#149038)
Variable templates are a bit lighter on the compiler than class templates.
1 parent b291d1a commit 4993f5b

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

libcxx/include/string

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -700,18 +700,18 @@ __concatenate_strings(const _Allocator& __alloc,
700700
__type_identity_t<basic_string_view<_CharT, _Traits> > __str2);
701701

702702
template <class _Iter>
703-
struct __string_is_trivial_iterator : public false_type {};
703+
inline const bool __string_is_trivial_iterator_v = false;
704704

705705
template <class _Tp>
706-
struct __string_is_trivial_iterator<_Tp*> : public is_arithmetic<_Tp> {};
706+
inline const bool __string_is_trivial_iterator_v<_Tp*> = is_arithmetic<_Tp>::value;
707707

708708
template <class _Iter>
709-
struct __string_is_trivial_iterator<__wrap_iter<_Iter> > : public __string_is_trivial_iterator<_Iter> {};
709+
inline const bool __string_is_trivial_iterator_v<__wrap_iter<_Iter> > = __string_is_trivial_iterator_v<_Iter>;
710710

711711
template <class _CharT, class _Traits, class _Tp>
712-
struct __can_be_converted_to_string_view
713-
: public _BoolConstant< is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
714-
!is_convertible<const _Tp&, const _CharT*>::value > {};
712+
inline const bool __can_be_converted_to_string_view_v =
713+
is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
714+
!is_convertible<const _Tp&, const _CharT*>::value;
715715

716716
struct __uninitialized_size_tag {};
717717
struct __init_with_sentinel_tag {};
@@ -1125,7 +1125,7 @@ public:
11251125
}
11261126

11271127
template <class _Tp,
1128-
__enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
1128+
__enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp> &&
11291129
!is_same<__remove_cvref_t<_Tp>, basic_string>::value,
11301130
int> = 0>
11311131
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
@@ -1137,7 +1137,7 @@ public:
11371137
}
11381138

11391139
template <class _Tp,
1140-
__enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
1140+
__enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp> &&
11411141
!is_same<__remove_cvref_t<_Tp>, basic_string>::value,
11421142
int> = 0>
11431143
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string(const _Tp& __t) {
@@ -1146,7 +1146,7 @@ public:
11461146
}
11471147

11481148
template <class _Tp,
1149-
__enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
1149+
__enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp> &&
11501150
!is_same<__remove_cvref_t<_Tp>, basic_string>::value,
11511151
int> = 0>
11521152
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string(const _Tp& __t, const allocator_type& __a)
@@ -1205,7 +1205,7 @@ public:
12051205
operator=(const basic_string& __str);
12061206

12071207
template <class _Tp,
1208-
__enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
1208+
__enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp> &&
12091209
!is_same<__remove_cvref_t<_Tp>, basic_string>::value,
12101210
int> = 0>
12111211
_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(const _Tp& __t) {
@@ -1342,7 +1342,7 @@ public:
13421342
}
13431343

13441344
template <class _Tp,
1345-
__enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
1345+
__enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp> &&
13461346
!is_same<__remove_cvref_t<_Tp>, basic_string >::value,
13471347
int> = 0>
13481348
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator+=(const _Tp& __t) {
@@ -1371,7 +1371,7 @@ public:
13711371
}
13721372

13731373
template <class _Tp,
1374-
__enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
1374+
__enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp> &&
13751375
!is_same<__remove_cvref_t<_Tp>, basic_string>::value,
13761376
int> = 0>
13771377
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const _Tp& __t) {
@@ -1382,7 +1382,7 @@ public:
13821382
_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const basic_string& __str, size_type __pos, size_type __n = npos);
13831383

13841384
template <class _Tp,
1385-
__enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
1385+
__enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp> &&
13861386
!is_same<__remove_cvref_t<_Tp>, basic_string>::value,
13871387
int> = 0>
13881388
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
@@ -1415,7 +1415,7 @@ public:
14151415
size_type __cap = capacity();
14161416
size_type __n = static_cast<size_type>(std::distance(__first, __last));
14171417
if (__n) {
1418-
if (__string_is_trivial_iterator<_ForwardIterator>::value && !__addr_in_range(*__first)) {
1418+
if (__string_is_trivial_iterator_v<_ForwardIterator> && !__addr_in_range(*__first)) {
14191419
if (__cap - __sz < __n)
14201420
__grow_by_without_replace(__cap, __sz + __n - __cap, __sz, __sz, 0);
14211421
__annotate_increase(__n);
@@ -1467,7 +1467,7 @@ public:
14671467
return *(data() + size() - 1);
14681468
}
14691469

1470-
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1470+
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp>, int> = 0>
14711471
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(const _Tp& __t) {
14721472
__self_view __sv = __t;
14731473
return assign(__sv.data(), __sv.size());
@@ -1509,7 +1509,7 @@ public:
15091509
_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n = npos);
15101510

15111511
template <class _Tp,
1512-
__enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
1512+
__enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp> &&
15131513
!is_same<__remove_cvref_t<_Tp>, basic_string>::value,
15141514
int> = 0>
15151515
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
@@ -1535,7 +1535,7 @@ public:
15351535
template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
15361536
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
15371537
assign(_ForwardIterator __first, _ForwardIterator __last) {
1538-
if (__string_is_trivial_iterator<_ForwardIterator>::value) {
1538+
if (__string_is_trivial_iterator_v<_ForwardIterator>) {
15391539
size_type __n = static_cast<size_type>(std::distance(__first, __last));
15401540
__assign_trivial(__first, __last, __n);
15411541
} else {
@@ -1548,7 +1548,7 @@ public:
15481548
# if _LIBCPP_STD_VER >= 23
15491549
template <_ContainerCompatibleRange<_CharT> _Range>
15501550
_LIBCPP_HIDE_FROM_ABI constexpr basic_string& assign_range(_Range&& __range) {
1551-
if constexpr (__string_is_trivial_iterator<ranges::iterator_t<_Range>>::value &&
1551+
if constexpr (__string_is_trivial_iterator_v<ranges::iterator_t<_Range>> &&
15521552
(ranges::forward_range<_Range> || ranges::sized_range<_Range>)) {
15531553
size_type __n = static_cast<size_type>(ranges::distance(__range));
15541554
__assign_trivial(ranges::begin(__range), ranges::end(__range), __n);
@@ -1572,14 +1572,14 @@ public:
15721572
return insert(__pos1, __str.data(), __str.size());
15731573
}
15741574

1575-
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1575+
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp>, int> = 0>
15761576
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos1, const _Tp& __t) {
15771577
__self_view __sv = __t;
15781578
return insert(__pos1, __sv.data(), __sv.size());
15791579
}
15801580

15811581
template <class _Tp,
1582-
__enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
1582+
__enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp> &&
15831583
!is_same<__remove_cvref_t<_Tp>, basic_string>::value,
15841584
int> = 0>
15851585
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
@@ -1649,7 +1649,7 @@ public:
16491649
return replace(__pos1, __n1, __str.data(), __str.size());
16501650
}
16511651

1652-
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1652+
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp>, int> = 0>
16531653
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
16541654
replace(size_type __pos1, size_type __n1, const _Tp& __t) {
16551655
__self_view __sv = __t;
@@ -1660,7 +1660,7 @@ public:
16601660
replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2 = npos);
16611661

16621662
template <class _Tp,
1663-
__enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
1663+
__enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp> &&
16641664
!is_same<__remove_cvref_t<_Tp>, basic_string>::value,
16651665
int> = 0>
16661666
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
@@ -1683,7 +1683,7 @@ public:
16831683
static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __str.data(), __str.size());
16841684
}
16851685

1686-
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1686+
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp>, int> = 0>
16871687
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
16881688
replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) {
16891689
__self_view __sv = __t;
@@ -1776,7 +1776,7 @@ public:
17761776
return std::__str_find<value_type, size_type, traits_type, npos>(data(), size(), __str.data(), __pos, __str.size());
17771777
}
17781778

1779-
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1779+
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp>, int> = 0>
17801780
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
17811781
find(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT {
17821782
__self_view __sv = __t;
@@ -1807,7 +1807,7 @@ public:
18071807
data(), size(), __str.data(), __pos, __str.size());
18081808
}
18091809

1810-
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1810+
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp>, int> = 0>
18111811
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
18121812
rfind(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT {
18131813
__self_view __sv = __t;
@@ -1838,7 +1838,7 @@ public:
18381838
data(), size(), __str.data(), __pos, __str.size());
18391839
}
18401840

1841-
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1841+
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp>, int> = 0>
18421842
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
18431843
find_first_of(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT {
18441844
__self_view __sv = __t;
@@ -1872,7 +1872,7 @@ public:
18721872
data(), size(), __str.data(), __pos, __str.size());
18731873
}
18741874

1875-
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1875+
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp>, int> = 0>
18761876
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
18771877
find_last_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT {
18781878
__self_view __sv = __t;
@@ -1906,7 +1906,7 @@ public:
19061906
data(), size(), __str.data(), __pos, __str.size());
19071907
}
19081908

1909-
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1909+
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp>, int> = 0>
19101910
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
19111911
find_first_not_of(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT {
19121912
__self_view __sv = __t;
@@ -1940,7 +1940,7 @@ public:
19401940
data(), size(), __str.data(), __pos, __str.size());
19411941
}
19421942

1943-
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1943+
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp>, int> = 0>
19441944
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
19451945
find_last_not_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT {
19461946
__self_view __sv = __t;
@@ -1972,7 +1972,7 @@ public:
19721972
return compare(__self_view(__str));
19731973
}
19741974

1975-
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1975+
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp>, int> = 0>
19761976
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 int compare(const _Tp& __t) const _NOEXCEPT {
19771977
__self_view __sv = __t;
19781978
size_t __lhs_sz = size();
@@ -1987,7 +1987,7 @@ public:
19871987
return 0;
19881988
}
19891989

1990-
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1990+
template <class _Tp, __enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp>, int> = 0>
19911991
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 int
19921992
compare(size_type __pos1, size_type __n1, const _Tp& __t) const {
19931993
__self_view __sv = __t;
@@ -2005,7 +2005,7 @@ public:
20052005
}
20062006

20072007
template <class _Tp,
2008-
__enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
2008+
__enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp> &&
20092009
!is_same<__remove_cvref_t<_Tp>, basic_string>::value,
20102010
int> = 0>
20112011
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 int
@@ -2951,7 +2951,7 @@ template <class _Iterator, class _Sentinel>
29512951
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
29522952
basic_string<_CharT, _Traits, _Allocator>::__assign_trivial(_Iterator __first, _Sentinel __last, size_type __n) {
29532953
_LIBCPP_ASSERT_INTERNAL(
2954-
__string_is_trivial_iterator<_Iterator>::value, "The iterator type given to `__assign_trivial` must be trivial");
2954+
__string_is_trivial_iterator_v<_Iterator>, "The iterator type given to `__assign_trivial` must be trivial");
29552955

29562956
size_type __old_size = size();
29572957
size_type __cap = capacity();
@@ -3166,7 +3166,7 @@ basic_string<_CharT, _Traits, _Allocator>::__insert_with_size(
31663166
if (__n == 0)
31673167
return begin() + __ip;
31683168

3169-
if (__string_is_trivial_iterator<_Iterator>::value && !__addr_in_range(*__first)) {
3169+
if (__string_is_trivial_iterator_v<_Iterator> && !__addr_in_range(*__first)) {
31703170
return __insert_from_safe_copy(__n, __ip, std::move(__first), std::move(__last));
31713171
} else {
31723172
const basic_string __temp(__init_with_sentinel_tag(), std::move(__first), std::move(__last), __alloc_);

0 commit comments

Comments
 (0)