[libcxx] r323152 - Another batch of P0202 constepr algirithms. remove/remove_if/remove_copy/remove_copy_if/reverse_copy, and tests (commented out) for rotate_copy, because that depends on std::copy
Marshall Clow via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 22 13:43:04 PST 2018
Author: marshall
Date: Mon Jan 22 13:43:04 2018
New Revision: 323152
URL: http://llvm.org/viewvc/llvm-project?rev=323152&view=rev
Log:
Another batch of P0202 constepr algirithms. remove/remove_if/remove_copy/remove_copy_if/reverse_copy, and tests (commented out) for rotate_copy, because that depends on std::copy
Modified:
libcxx/trunk/include/algorithm
libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.remove/remove.pass.cpp
libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy.pass.cpp
libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy_if.pass.cpp
libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.remove/remove_if.pass.cpp
libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.reverse/reverse_copy.pass.cpp
libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate_copy.pass.cpp
Modified: libcxx/trunk/include/algorithm
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=323152&r1=323151&r2=323152&view=diff
==============================================================================
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Mon Jan 22 13:43:04 2018
@@ -236,19 +236,19 @@ template <class OutputIterator, class Si
generate_n(OutputIterator first, Size n, Generator gen);
template <class ForwardIterator, class T>
- ForwardIterator
+ constexpr ForwardIterator // constexpr in C++20
remove(ForwardIterator first, ForwardIterator last, const T& value);
template <class ForwardIterator, class Predicate>
- ForwardIterator
+ constexpr ForwardIterator // constexpr in C++20
remove_if(ForwardIterator first, ForwardIterator last, Predicate pred);
template <class InputIterator, class OutputIterator, class T>
- OutputIterator
+ constexpr OutputIterator // constexpr in C++20
remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value);
template <class InputIterator, class OutputIterator, class Predicate>
- OutputIterator
+ constexpr OutputIterator // constexpr in C++20
remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred);
template <class ForwardIterator>
@@ -272,7 +272,7 @@ template <class BidirectionalIterator>
reverse(BidirectionalIterator first, BidirectionalIterator last);
template <class BidirectionalIterator, class OutputIterator>
- OutputIterator
+ constexpr OutputIterator // constexpr in C++20
reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result);
template <class ForwardIterator>
@@ -2098,7 +2098,7 @@ generate_n(_OutputIterator __first, _Siz
// remove
template <class _ForwardIterator, class _Tp>
-_ForwardIterator
+_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
{
__first = _VSTD::find(__first, __last, __value_);
@@ -2120,7 +2120,7 @@ remove(_ForwardIterator __first, _Forwar
// remove_if
template <class _ForwardIterator, class _Predicate>
-_ForwardIterator
+_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
{
__first = _VSTD::find_if<_ForwardIterator, typename add_lvalue_reference<_Predicate>::type>
@@ -2143,7 +2143,7 @@ remove_if(_ForwardIterator __first, _For
// remove_copy
template <class _InputIterator, class _OutputIterator, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, const _Tp& __value_)
{
@@ -2161,7 +2161,7 @@ remove_copy(_InputIterator __first, _Inp
// remove_copy_if
template <class _InputIterator, class _OutputIterator, class _Predicate>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
remove_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred)
{
@@ -2327,7 +2327,7 @@ reverse(_BidirectionalIterator __first,
// reverse_copy
template <class _BidirectionalIterator, class _OutputIterator>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result)
{
Modified: libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.remove/remove.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.remove/remove.pass.cpp?rev=323152&r1=323151&r2=323152&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.remove/remove.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.remove/remove.pass.cpp Mon Jan 22 13:43:04 2018
@@ -12,7 +12,7 @@
// template<ForwardIterator Iter, class T>
// requires OutputIterator<Iter, RvalueOf<Iter::reference>::type>
// && HasEqualTo<Iter::value_type, T>
-// Iter
+// constexpr Iter // constexpr after C++17
// remove(Iter first, Iter last, const T& value);
#include <algorithm>
@@ -22,6 +22,18 @@
#include "test_macros.h"
#include "test_iterators.h"
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_constexpr() {
+ int ia[] = {1, 3, 5, 2, 5, 6};
+
+ auto it = std::remove(std::begin(ia), std::end(ia), 5);
+
+ return (std::begin(ia) + std::size(ia) - 2) == it // we removed two elements
+ && std::none_of(std::begin(ia), it, [](int a) {return a == 5; })
+ ;
+ }
+#endif
+
template <class Iter>
void
test()
@@ -75,4 +87,8 @@ int main()
test1<random_access_iterator<std::unique_ptr<int>*> >();
test1<std::unique_ptr<int>*>();
#endif // TEST_STD_VER >= 11
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
Modified: libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy.pass.cpp?rev=323152&r1=323151&r2=323152&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy.pass.cpp Mon Jan 22 13:43:04 2018
@@ -11,14 +11,29 @@
// template<InputIterator InIter, OutputIterator<auto, InIter::reference> OutIter, class T>
// requires HasEqualTo<InIter::value_type, T>
-// OutIter
+// constexpr OutIter // constexpr after C++17
// remove_copy(InIter first, InIter last, OutIter result, const T& value);
#include <algorithm>
#include <cassert>
+#include "test_macros.h"
#include "test_iterators.h"
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_constexpr() {
+ int ia[] = {1, 3, 5, 2, 5, 6};
+ int ib[std::size(ia)] = {0};
+
+ auto it = std::remove_copy(std::begin(ia), std::end(ia), std::begin(ib), 5);
+
+ return std::distance(std::begin(ib), it) == (std::size(ia) - 2) // we removed two elements
+ && std::none_of(std::begin(ib), it, [](int a) {return a == 5;})
+ && std::all_of (it, std::end(ib), [](int a) {return a == 0;})
+ ;
+ }
+#endif
+
template <class InIter, class OutIter>
void
test()
@@ -67,4 +82,8 @@ int main()
test<const int*, bidirectional_iterator<int*> >();
test<const int*, random_access_iterator<int*> >();
test<const int*, int*>();
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
Modified: libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy_if.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy_if.pass.cpp?rev=323152&r1=323151&r2=323152&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy_if.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy_if.pass.cpp Mon Jan 22 13:43:04 2018
@@ -12,16 +12,31 @@
// template<InputIterator InIter, OutputIterator<auto, InIter::reference> OutIter,
// Predicate<auto, InIter::value_type> Pred>
// requires CopyConstructible<Pred>
-// OutIter
+// constexpr OutIter // constexpr after C++17
// remove_copy_if(InIter first, InIter last, OutIter result, Pred pred);
#include <algorithm>
#include <functional>
#include <cassert>
+#include "test_macros.h"
#include "test_iterators.h"
-bool equalToTwo(int v) { return v == 2; }
+TEST_CONSTEXPR bool equalToTwo(int v) { return v == 2; }
+
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_constexpr() {
+ int ia[] = {1, 3, 5, 2, 5, 6};
+ int ib[std::size(ia)] = {0};
+
+ auto it = std::remove_copy_if(std::begin(ia), std::end(ia), std::begin(ib), equalToTwo);
+
+ return std::distance(std::begin(ib), it) == (std::size(ia) - 1) // we removed one element
+ && std::none_of(std::begin(ib), it, equalToTwo)
+ && std::all_of (it, std::end(ib), [](int a) {return a == 0;})
+ ;
+ }
+#endif
template <class InIter, class OutIter>
void
@@ -72,4 +87,8 @@ int main()
test<const int*, bidirectional_iterator<int*> >();
test<const int*, random_access_iterator<int*> >();
test<const int*, int*>();
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
Modified: libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.remove/remove_if.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.remove/remove_if.pass.cpp?rev=323152&r1=323151&r2=323152&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.remove/remove_if.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.remove/remove_if.pass.cpp Mon Jan 22 13:43:04 2018
@@ -12,7 +12,7 @@
// template<ForwardIterator Iter, Predicate<auto, Iter::value_type> Pred>
// requires OutputIterator<Iter, RvalueOf<Iter::reference>::type>
// && CopyConstructible<Pred>
-// Iter
+// constexpr Iter // constexpr after C++17
// remove_if(Iter first, Iter last, Pred pred);
#include <algorithm>
@@ -24,7 +24,19 @@
#include "test_iterators.h"
#include "counting_predicates.hpp"
-bool equal2 ( int i ) { return i == 2; }
+TEST_CONSTEXPR bool equal2 ( int i ) { return i == 2; }
+
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_constexpr() {
+ int ia[] = {1, 3, 5, 2, 5, 6};
+
+ auto it = std::remove_if(std::begin(ia), std::end(ia), equal2);
+
+ return (std::begin(ia) + std::size(ia) - 1) == it // we removed one element
+ && std::none_of(std::begin(ia), it, equal2)
+ ;
+ }
+#endif
template <class Iter>
void
@@ -90,4 +102,8 @@ int main()
test1<random_access_iterator<std::unique_ptr<int>*> >();
test1<std::unique_ptr<int>*>();
#endif // TEST_STD_VER >= 11
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
Modified: libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.reverse/reverse_copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.reverse/reverse_copy.pass.cpp?rev=323152&r1=323151&r2=323152&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.reverse/reverse_copy.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.reverse/reverse_copy.pass.cpp Mon Jan 22 13:43:04 2018
@@ -10,14 +10,28 @@
// <algorithm>
// template<BidirectionalIterator InIter, OutputIterator<auto, InIter::reference> OutIter>
-// OutIter
+// constexpr OutIter // constexpr after C++17
// reverse_copy(InIter first, InIter last, OutIter result);
#include <algorithm>
#include <cassert>
+#include "test_macros.h"
#include "test_iterators.h"
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_constexpr() {
+ int ia[] = {1, 3, 5, 2, 5, 6};
+ int ib[std::size(ia)] = {0};
+
+ auto it = std::reverse_copy(std::begin(ia), std::end(ia), std::begin(ib));
+
+ return std::distance(std::begin(ib), it) == std::size(ia)
+ && std::equal (std::begin(ia), std::end(ia), std::rbegin(ib))
+ ;
+ }
+#endif
+
template <class InIter, class OutIter>
void
test()
@@ -78,4 +92,8 @@ int main()
test<const int*, bidirectional_iterator<int*> >();
test<const int*, random_access_iterator<int*> >();
test<const int*, int*>();
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
Modified: libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate_copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate_copy.pass.cpp?rev=323152&r1=323151&r2=323152&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate_copy.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate_copy.pass.cpp Mon Jan 22 13:43:04 2018
@@ -10,14 +10,31 @@
// <algorithm>
// template<ForwardIterator InIter, OutputIterator<auto, InIter::reference> OutIter>
-// OutIter
+// constexpr OutIter // constexpr after C++17
// rotate_copy(InIter first, InIter middle, InIter last, OutIter result);
#include <algorithm>
#include <cassert>
+#include "test_macros.h"
#include "test_iterators.h"
+// #if TEST_STD_VER > 17
+// TEST_CONSTEXPR bool test_constexpr() {
+// int ia[] = {1, 3, 5, 2, 5, 6};
+// int ib[std::size(ia)] = {0};
+//
+// const size_t N = 2;
+// const auto middle = std::begin(ia) + N;
+// auto it = std::rotate_copy(std::begin(ia), middle, std::end(ia), std::begin(ib));
+//
+// return std::distance(std::begin(ib), it) == std::size(ia)
+// && std::equal (std::begin(ia), middle, std::begin(ib) + std::size(ia) - N)
+// && std::equal (middle, std::end(ia), std::begin(ib))
+// ;
+// }
+// #endif
+
template <class InIter, class OutIter>
void
test()
@@ -131,4 +148,8 @@ int main()
test<const int*, bidirectional_iterator<int*> >();
test<const int*, random_access_iterator<int*> >();
test<const int*, int*>();
+
+// #if TEST_STD_VER > 17
+// static_assert(test_constexpr());
+// #endif
}
More information about the cfe-commits
mailing list