Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc constexpr #491

Merged
merged 40 commits into from
May 23, 2020
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
539c4e6
Fix incorrect constexpr qualification of string_view::copy
miscco Feb 7, 2020
3a70a44
Make pair::operator= constexpr
miscco Feb 7, 2020
9e383e2
Make swap overload of pair constexpr
miscco Feb 7, 2020
7f74b86
Make tuple constexpr
miscco Feb 7, 2020
e4dcd53
Make array::swap constexpr
miscco Mar 3, 2020
c10d3a9
Make array::fill constexpr
miscco Feb 7, 2020
0d16293
Make back_insert_iterator constexpr
miscco Feb 7, 2020
237138b
Make front_insert_iterator constexpr
miscco Feb 7, 2020
a7a3b4b
Make insert_iterator constexpr
miscco Feb 7, 2020
5c40bc5
Make default_searcher constexpr
miscco Feb 7, 2020
64d7a60
Add feature test macros
miscco Feb 7, 2020
f83b08c
Rename and properly list P1032R1_miscellaneous_constexpr.
StephanTLavavej Apr 11, 2020
b82927c
List feature, add/test feature-test macros.
StephanTLavavej Apr 11, 2020
5a88857
Don't mark a deleted operator as constexpr.
StephanTLavavej Apr 11, 2020
7c8d6bb
Add review changes from STL
miscco Apr 11, 2020
3a38a1f
[string] More constexpr
miscco Apr 11, 2020
6d8a6b5
Fix unused variable warning
miscco Apr 13, 2020
c2efcf1
Add check for string test
miscco Apr 13, 2020
768ad63
Apply suggestions from code review
miscco Apr 13, 2020
b345b63
Make internal machinery unconditionally constexpr
miscco Apr 13, 2020
49f8dd2
{xstring] Guard against overlapping ranges
miscco Apr 15, 2020
8ed8cd9
Supress spurious warning
miscco May 13, 2020
8c37084
Use __builtins when available
miscco May 16, 2020
2bb3b56
Redirect please
miscco May 17, 2020
3a99fb8
Merge branch 'master' into misc_constexpr
StephanTLavavej May 19, 2020
86484e5
Add missing return statement.
StephanTLavavej May 19, 2020
ffff3c6
Adjust preprocessor comments.
StephanTLavavej May 19, 2020
0dae04a
Update libcxx results.
StephanTLavavej May 20, 2020
1e8ad54
Fix "unused variable" test warnings.
StephanTLavavej May 20, 2020
ffe2016
Adjust preprocessor comments.
StephanTLavavej May 20, 2020
bba486c
Code review feedback.
StephanTLavavej May 21, 2020
8571e0a
Simplify is_constant_evaluated logic.
StephanTLavavej May 21, 2020
b2ddb60
Improve consistency.
StephanTLavavej May 21, 2020
fd291a8
Fix char_traits for all compilers.
StephanTLavavej May 21, 2020
b29339b
Review and extend tests.
StephanTLavavej May 22, 2020
b92e9a0
Fix comment typo, enhance comments.
StephanTLavavej May 22, 2020
1a726b4
Centralize _HAS_MEMCPY_MEMMOVE_INTRINSICS.
StephanTLavavej May 22, 2020
ea49f51
Code review feedback: Call _Primary_char_traits::assign.
StephanTLavavej May 23, 2020
5c178c0
Inherit from _Primary_char_traits to reduce code duplication.
StephanTLavavej May 23, 2020
3c0fbbd
Add comments and reorder functions.
StephanTLavavej May 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions stl/inc/array
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,11 @@ public:
}
#endif // _HAS_TR1_NAMESPACE

void fill(const _Ty& _Value) {
_CONSTEXPR20 void fill(const _Ty& _Value) {
_STD fill_n(_Elems, _Size, _Value);
}

void swap(array& _Other) noexcept(_Is_nothrow_swappable<_Ty>::value) {
_CONSTEXPR20 void swap(array& _Other) noexcept(_Is_nothrow_swappable<_Ty>::value) {
_Swap_ranges_unchecked(_Elems, _Elems + _Size, _Other._Elems);
}

Expand Down Expand Up @@ -618,9 +618,9 @@ public:
_DEPRECATE_TR1_NAMESPACE void assign(const _Ty&) {}
#endif // _HAS_TR1_NAMESPACE

void fill(const _Ty&) {}
_CONSTEXPR20 void fill(const _Ty&) {}

void swap(array&) noexcept {}
_CONSTEXPR20 void swap(array&) noexcept {}

_NODISCARD _CONSTEXPR17 iterator begin() noexcept {
return iterator{};
Expand Down Expand Up @@ -770,7 +770,7 @@ public:
};

template <class _Ty, size_t _Size, enable_if_t<_Size == 0 || _Is_swappable<_Ty>::value, int> = 0>
void swap(array<_Ty, _Size>& _Left, array<_Ty, _Size>& _Right) noexcept(noexcept(_Left.swap(_Right))) {
_CONSTEXPR20 void swap(array<_Ty, _Size>& _Left, array<_Ty, _Size>& _Right) noexcept(noexcept(_Left.swap(_Right))) {
return _Left.swap(_Right);
}

Expand Down
9 changes: 5 additions & 4 deletions stl/inc/functional
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,7 @@ struct _Global_delete {

// CLASS TEMPLATE default_searcher
template <class _FwdItHaystack, class _FwdItPat, class _Pred_eq>
pair<_FwdItHaystack, _FwdItHaystack> _Search_pair_unchecked(_FwdItHaystack _First1, _FwdItHaystack _Last1,
_CONSTEXPR20 pair<_FwdItHaystack, _FwdItHaystack> _Search_pair_unchecked(_FwdItHaystack _First1, _FwdItHaystack _Last1,
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
_FwdItPat _First2, _FwdItPat _Last2, _Pred_eq& _Eq, forward_iterator_tag, forward_iterator_tag) {
// find first [_First2, _Last2) satisfying _Eq, arbitrary iterators
for (;; ++_First1) { // loop until match or end of a sequence
Expand All @@ -1634,7 +1634,7 @@ pair<_FwdItHaystack, _FwdItHaystack> _Search_pair_unchecked(_FwdItHaystack _Firs
}

template <class _FwdItHaystack, class _FwdItPat, class _Pred_eq>
pair<_FwdItHaystack, _FwdItHaystack> _Search_pair_unchecked(_FwdItHaystack _First1, _FwdItHaystack _Last1,
_CONSTEXPR20 pair<_FwdItHaystack, _FwdItHaystack> _Search_pair_unchecked(_FwdItHaystack _First1, _FwdItHaystack _Last1,
_FwdItPat _First2, _FwdItPat _Last2, _Pred_eq& _Eq, random_access_iterator_tag, random_access_iterator_tag) {
// find first [_First2, _Last2) satisfying _Eq, random-access iterators
_Iter_diff_t<_FwdItHaystack> _Count1 = _Last1 - _First1;
Expand All @@ -1659,14 +1659,15 @@ pair<_FwdItHaystack, _FwdItHaystack> _Search_pair_unchecked(_FwdItHaystack _Firs
template <class _FwdItPat, class _Pred_eq = equal_to<>>
class default_searcher { // functor to search haystacks for needles
public:
default_searcher(_FwdItPat _First, _FwdItPat _Last, _Pred_eq _Eq = _Pred_eq())
_CONSTEXPR20 default_searcher(_FwdItPat _First, _FwdItPat _Last, _Pred_eq _Eq = _Pred_eq())
: _Data{_One_then_variadic_args_t{}, _STD move(_Eq), pair<_FwdItPat, _FwdItPat>{_First, _Last}} {
const auto& _Pat = _Data._Myval2;
_Adl_verify_range(_Pat.first, _Pat.second);
}

template <class _FwdItHaystack>
_NODISCARD pair<_FwdItHaystack, _FwdItHaystack> operator()(_FwdItHaystack _First, _FwdItHaystack _Last) const {
_NODISCARD _CONSTEXPR20 pair<_FwdItHaystack, _FwdItHaystack> operator()(
_FwdItHaystack _First, _FwdItHaystack _Last) const {
// search [_First, _Last) for the searcher's pattern
_Adl_verify_range(_First, _Last);
const auto& _Eq = _Data._Get_first();
Expand Down
44 changes: 23 additions & 21 deletions stl/inc/iterator
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,28 @@ public:
using difference_type = void;
#endif // __cpp_lib_concepts

explicit back_insert_iterator(_Container& _Cont) noexcept /* strengthened */ : container(_STD addressof(_Cont)) {}
_CONSTEXPR20 explicit back_insert_iterator(_Container& _Cont) noexcept /* strengthened */
: container(_STD addressof(_Cont)) {}

back_insert_iterator& operator=(const typename _Container::value_type& _Val) {
_CONSTEXPR20 back_insert_iterator& operator=(const typename _Container::value_type& _Val) {
container->push_back(_Val);
return *this;
}

back_insert_iterator& operator=(typename _Container::value_type&& _Val) {
_CONSTEXPR20 back_insert_iterator& operator=(typename _Container::value_type&& _Val) {
container->push_back(_STD move(_Val));
return *this;
}

_NODISCARD back_insert_iterator& operator*() noexcept /* strengthened */ {
_NODISCARD _CONSTEXPR20 back_insert_iterator& operator*() noexcept /* strengthened */ {
return *this;
}

back_insert_iterator& operator++() noexcept /* strengthened */ {
_CONSTEXPR20 back_insert_iterator& operator++() noexcept /* strengthened */ {
return *this;
}

back_insert_iterator operator++(int) noexcept /* strengthened */ {
_CONSTEXPR20 back_insert_iterator operator++(int) noexcept /* strengthened */ {
return *this;
}

Expand All @@ -68,7 +69,7 @@ protected:

// FUNCTION TEMPLATE back_inserter
template <class _Container>
_NODISCARD back_insert_iterator<_Container> back_inserter(_Container& _Cont) noexcept /* strengthened */ {
_NODISCARD _CONSTEXPR20 back_insert_iterator<_Container> back_inserter(_Container& _Cont) noexcept /* strengthened */ {
// return a back_insert_iterator
return back_insert_iterator<_Container>(_Cont);
}
Expand All @@ -92,27 +93,28 @@ public:
using difference_type = void;
#endif // __cpp_lib_concepts

explicit front_insert_iterator(_Container& _Cont) : container(_STD addressof(_Cont)) {}
_CONSTEXPR20 explicit front_insert_iterator(_Container& _Cont) : container(_STD addressof(_Cont)) {}

front_insert_iterator& operator=(const typename _Container::value_type& _Val) { // push value into container
_CONSTEXPR20 front_insert_iterator& operator=(const typename _Container::value_type& _Val) {
// push value into container
container->push_front(_Val);
return *this;
}

front_insert_iterator& operator=(typename _Container::value_type&& _Val) { // push value into container
_CONSTEXPR20 front_insert_iterator& operator=(typename _Container::value_type&& _Val) { // push value into container
container->push_front(_STD move(_Val));
return *this;
}

_NODISCARD front_insert_iterator& operator*() { // pretend to return designated value
_NODISCARD _CONSTEXPR20 front_insert_iterator& operator*() { // pretend to return designated value
return *this;
}

front_insert_iterator& operator++() { // pretend to preincrement
_CONSTEXPR20 front_insert_iterator& operator++() { // pretend to preincrement
return *this;
}

front_insert_iterator operator++(int) { // pretend to postincrement
_CONSTEXPR20 front_insert_iterator operator++(int) { // pretend to postincrement
return *this;
}

Expand All @@ -122,7 +124,7 @@ protected:

// FUNCTION TEMPLATE front_inserter
template <class _Container>
_NODISCARD front_insert_iterator<_Container> front_inserter(_Container& _Cont) {
_NODISCARD _CONSTEXPR20 front_insert_iterator<_Container> front_inserter(_Container& _Cont) {
return front_insert_iterator<_Container>(_Cont);
}

Expand All @@ -146,32 +148,32 @@ public:
using difference_type = void;
#endif // __cpp_lib_concepts

insert_iterator(_Container& _Cont, typename _Container::iterator _Where)
_CONSTEXPR20 insert_iterator(_Container& _Cont, typename _Container::iterator _Where)
: container(_STD addressof(_Cont)), iter(_Where) {}

insert_iterator& operator=(
_CONSTEXPR20 insert_iterator& operator=(
const typename _Container::value_type& _Val) { // insert into container and increment stored iterator
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
iter = container->insert(iter, _Val);
++iter;
return *this;
}

insert_iterator& operator=(typename _Container::value_type&& _Val) { // push value into container
_CONSTEXPR20 insert_iterator& operator=(typename _Container::value_type&& _Val) { // push value into container

StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
iter = container->insert(iter, _STD move(_Val));
++iter;
return *this;
}

_NODISCARD insert_iterator& operator*() { // pretend to return designated value
_NODISCARD _CONSTEXPR20 insert_iterator& operator*() { // pretend to return designated value
return *this;
}

insert_iterator& operator++() { // pretend to preincrement
_CONSTEXPR20 insert_iterator& operator++() { // pretend to preincrement
return *this;
}

insert_iterator& operator++(int) { // pretend to postincrement
_CONSTEXPR20 insert_iterator& operator++(int) { // pretend to postincrement
return *this;
}

Expand All @@ -182,7 +184,7 @@ protected:

// FUNCTION TEMPLATE inserter
template <class _Container>
_NODISCARD insert_iterator<_Container> inserter(_Container& _Cont, typename _Container::iterator _Where) {
_NODISCARD _CONSTEXPR20 insert_iterator<_Container> inserter(_Container& _Cont, typename _Container::iterator _Where) {
return insert_iterator<_Container>(_Cont, _Where);
}

Expand Down
Loading