Last batch of P0202 constexpr additions: includes/set_intersection/exchange

llvm-svn: 323159
This commit is contained in:
Marshall Clow 2018-01-22 23:10:40 +00:00
parent 239d25a158
commit 8da1a487ae
7 changed files with 128 additions and 17 deletions

View File

@ -412,7 +412,7 @@ template <class ForwardIterator, class T>
binary_search(ForwardIterator first, ForwardIterator last, const T& value);
template <class ForwardIterator, class T, class Compare>
bool // constexpr in C++20
constexpr bool // constexpr in C++20
binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
template <class InputIterator1, class InputIterator2, class OutputIterator>
@ -434,11 +434,11 @@ template <class BidirectionalIterator, class Compare>
inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last, Compare comp);
template <class InputIterator1, class InputIterator2>
bool
constexpr bool // constexpr in C++20
includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
template <class InputIterator1, class InputIterator2, class Compare>
bool
constexpr bool // constexpr in C++20
includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp);
template <class InputIterator1, class InputIterator2, class OutputIterator>
@ -452,12 +452,12 @@ template <class InputIterator1, class InputIterator2, class OutputIterator, clas
InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
template <class InputIterator1, class InputIterator2, class OutputIterator>
OutputIterator
constexpr OutputIterator // constexpr in C++20
set_intersection(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2, OutputIterator result);
template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
OutputIterator
constexpr OutputIterator // constexpr in C++20
set_intersection(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
@ -5397,7 +5397,7 @@ nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomA
// includes
template <class _Compare, class _InputIterator1, class _InputIterator2>
bool
_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
__includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
_Compare __comp)
{
@ -5412,7 +5412,7 @@ __includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __
}
template <class _InputIterator1, class _InputIterator2, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
_Compare __comp)
@ -5428,7 +5428,7 @@ includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __fi
}
template <class _InputIterator1, class _InputIterator2>
inline _LIBCPP_INLINE_VISIBILITY
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2)
{
@ -5494,7 +5494,7 @@ set_union(_InputIterator1 __first1, _InputIterator1 __last1,
// set_intersection
template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
_OutputIterator
_LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
__set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
{
@ -5517,7 +5517,7 @@ __set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
}
template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
@ -5533,7 +5533,7 @@ set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
}
template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
inline _LIBCPP_INLINE_VISIBILITY
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result)

View File

@ -890,7 +890,7 @@ template<class... _Tp>
#if _LIBCPP_STD_VER > 11
template<class _T1, class _T2 = _T1>
inline _LIBCPP_INLINE_VISIBILITY
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_T1 exchange(_T1& __obj, _T2 && __new_value)
{
_T1 __old_value = _VSTD::move(__obj);

View File

@ -12,14 +12,27 @@
// template<InputIterator Iter1, InputIterator Iter2>
// requires HasLess<Iter1::value_type, Iter2::value_type>
// && HasLess<Iter2::value_type, Iter1::value_type>
// bool
// constexpr bool // constexpr after C++17
// includes(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2);
#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, 2, 2, 3, 3, 3, 4, 4, 4, 4};
int ib[] = {2, 4};
int ic[] = {3, 3, 3, 3};
return std::includes(std::begin(ia), std::end(ia), std::begin(ib), std::end(ib))
&& !std::includes(std::begin(ia), std::end(ia), std::begin(ic), std::end(ic))
;
}
#endif
template <class Iter1, class Iter2>
void
test()
@ -81,4 +94,8 @@ int main()
test<const int*, bidirectional_iterator<const int*> >();
test<const int*, random_access_iterator<const int*> >();
test<const int*, const int*>();
#if TEST_STD_VER > 17
static_assert(test_constexpr());
#endif
}

View File

@ -12,15 +12,30 @@
// template<InputIterator Iter1, InputIterator Iter2, typename Compare>
// requires Predicate<Compare, Iter1::value_type, Iter2::value_type>
// && Predicate<Compare, Iter2::value_type, Iter1::value_type>
// bool
// constexpr bool // constexpr after C++17
// includes(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2, Compare comp);
#include <algorithm>
#include <functional>
#include <cassert>
#include "test_macros.h"
#include "test_iterators.h"
#if TEST_STD_VER > 17
TEST_CONSTEXPR bool test_constexpr() {
int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
int ib[] = {2, 4};
int ic[] = {3, 3, 3, 3};
auto comp = [](int a, int b) {return a < b; };
return std::includes(std::begin(ia), std::end(ia), std::begin(ib), std::end(ib), comp)
&& !std::includes(std::begin(ia), std::end(ia), std::begin(ic), std::end(ic), comp)
;
}
#endif
template <class Iter1, class Iter2>
void
test()
@ -82,4 +97,8 @@ int main()
test<const int*, bidirectional_iterator<const int*> >();
test<const int*, random_access_iterator<const int*> >();
test<const int*, const int*>();
#if TEST_STD_VER > 17
static_assert(test_constexpr());
#endif
}

View File

@ -14,15 +14,34 @@
// && OutputIterator<OutIter, InIter2::reference>
// && HasLess<InIter2::value_type, InIter1::value_type>
// && HasLess<InIter1::value_type, InIter2::value_type>
// OutIter
// constpexr OutIter // constexpr after C++17
// set_intersection(InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2,
// OutIter result);
#include <algorithm>
#include <cassert>
#include "test_macros.h"
#include "test_iterators.h"
#if TEST_STD_VER > 17
TEST_CONSTEXPR bool test_constexpr() {
const int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
const int ib[] = {2, 4, 4, 6};
int results[std::size(ia)] = {0};
auto it = std::set_intersection(std::begin(ia), std::end(ia),
std::begin(ib), std::end(ib), std::begin(results));
return std::includes(std::begin(ia), std::end(ia), std::begin(results), it)
&& std::includes(std::begin(ib), std::end(ib), std::begin(results), it)
&& std::is_sorted(std::begin(results), it)
&& std::all_of(it, std::end(results), [](int a) {return a == 0; })
;
}
#endif
template <class Iter1, class Iter2, class OutIter>
void
test()
@ -195,4 +214,8 @@ int main()
test<const int*, const int*, bidirectional_iterator<int*> >();
test<const int*, const int*, random_access_iterator<int*> >();
test<const int*, const int*, int*>();
#if TEST_STD_VER > 17
static_assert(test_constexpr());
#endif
}

View File

@ -15,7 +15,7 @@
// && OutputIterator<OutIter, InIter2::reference>
// && Predicate<Compare, InIter1::value_type, InIter2::value_type>
// && Predicate<Compare, InIter2::value_type, InIter1::value_type>
// OutIter
// constpexr OutIter // constexpr after C++17
// set_intersection(InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2,
// OutIter result, Compare comp);
@ -23,8 +23,28 @@
#include <functional>
#include <cassert>
#include "test_macros.h"
#include "test_iterators.h"
#if TEST_STD_VER > 17
TEST_CONSTEXPR bool test_constexpr() {
const int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
const int ib[] = {2, 4, 4, 6};
int results[std::size(ia)] = {0};
auto comp = [](int a, int b) {return a < b; };
auto it = std::set_intersection(std::begin(ia), std::end(ia),
std::begin(ib), std::end(ib), std::begin(results), comp);
return std::includes(std::begin(ia), std::end(ia), std::begin(results), it)
&& std::includes(std::begin(ib), std::end(ib), std::begin(results), it)
&& std::is_sorted(std::begin(results), it, comp)
&& std::all_of(it, std::end(results), [](int a) {return a == 0; })
;
}
#endif
template <class Iter1, class Iter2, class OutIter>
void
test()
@ -197,4 +217,8 @@ int main()
test<const int*, const int*, bidirectional_iterator<int*> >();
test<const int*, const int*, random_access_iterator<int*> >();
test<const int*, const int*, int*>();
#if TEST_STD_VER > 17
static_assert(test_constexpr());
#endif
}

View File

@ -8,14 +8,38 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11
// utilities
// <utility>
// exchange
// template<class T, class U=T>
// constexpr T // constexpr after C++17
// exchange(T& obj, U&& new_value);
#include <utility>
#include <cassert>
#include <string>
#include "test_macros.h"
#if TEST_STD_VER > 17
TEST_CONSTEXPR bool test_constexpr() {
int v = 12;
if (12 != std::exchange(v,23) || v != 23)
return false;
if (23 != std::exchange(v,static_cast<short>(67)) || v != 67)
return false;
if (67 != std::exchange<int, short>(v, {}) || v != 0)
return false;
return true;
}
#endif
int main()
{
{
@ -53,4 +77,8 @@ int main()
assert ( std::exchange ( s3, "" ) == s2 );
assert ( s3.size () == 0 );
}
#if TEST_STD_VER > 17
static_assert(test_constexpr());
#endif
}