mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-23 01:18:52 +08:00
First part of P0202: Adding constexpr modifiers to functions in <algorithm> and <utility>. This commit is all the is_XXX algorithms.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@322489 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -11,12 +11,23 @@
|
||||
|
||||
// template<RandomAccessIterator Iter>
|
||||
// requires LessThanComparable<Iter::value_type>
|
||||
// bool
|
||||
// constexpr bool // constexpr after C++17
|
||||
// is_heap(Iter first, Iter last);
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
#if TEST_STD_VER > 17
|
||||
TEST_CONSTEXPR int test_constexpr() {
|
||||
int ia[] = {1, 1, 1, 1, 0, 1, 1};
|
||||
int ib[] = {0, 0, 1, 0, 0, 0, 0};
|
||||
return std::is_heap(std::begin(ia), std::end(ia))
|
||||
&& !std::is_heap(std::begin(ib), std::end(ib));
|
||||
}
|
||||
#endif
|
||||
|
||||
void test()
|
||||
{
|
||||
int i1[] = {0, 0};
|
||||
@@ -518,4 +529,8 @@ void test()
|
||||
int main()
|
||||
{
|
||||
test();
|
||||
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test_constexpr());
|
||||
#endif
|
||||
}
|
||||
|
@@ -11,13 +11,24 @@
|
||||
|
||||
// template<RandomAccessIterator Iter>
|
||||
// requires LessThanComparable<Iter::value_type>
|
||||
// bool
|
||||
// constexpr bool // constexpr after C++17
|
||||
// is_heap(Iter first, Iter last);
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
#if TEST_STD_VER > 17
|
||||
TEST_CONSTEXPR int test_constexpr() {
|
||||
int ia[] = {0, 0, 1, 1, 1};
|
||||
int ib[] = {1, 0, 4, 1, 0};
|
||||
return std::is_heap(std::begin(ia), std::end(ia), std::greater<int>())
|
||||
&& !std::is_heap(std::begin(ib), std::end(ib), std::greater<int>());
|
||||
}
|
||||
#endif
|
||||
|
||||
void test()
|
||||
{
|
||||
int i1[] = {0, 0};
|
||||
@@ -519,4 +530,8 @@ void test()
|
||||
int main()
|
||||
{
|
||||
test();
|
||||
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test_constexpr());
|
||||
#endif
|
||||
}
|
||||
|
@@ -11,12 +11,23 @@
|
||||
|
||||
// template<RandomAccessIterator Iter>
|
||||
// requires LessThanComparable<Iter::value_type>
|
||||
// Iter
|
||||
// constexpr bool // constexpr after C++17
|
||||
// is_heap_until(Iter first, Iter last);
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
#if TEST_STD_VER > 17
|
||||
TEST_CONSTEXPR int test_constexpr() {
|
||||
int ia[] = {0, 0, 0, 0, 1, 0};
|
||||
int ib[] = {0, 0, 0, 1, 1, 1};
|
||||
return (std::is_heap_until(std::begin(ia), std::end(ia)) == ia+4)
|
||||
&& (std::is_heap_until(std::begin(ib), std::end(ib)) == ib+3);
|
||||
}
|
||||
#endif
|
||||
|
||||
void test()
|
||||
{
|
||||
int i1[] = {0, 0};
|
||||
@@ -518,4 +529,8 @@ void test()
|
||||
int main()
|
||||
{
|
||||
test();
|
||||
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test_constexpr());
|
||||
#endif
|
||||
}
|
||||
|
@@ -11,13 +11,24 @@
|
||||
|
||||
// template<RandomAccessIterator Iter, StrictWeakOrder<auto, Iter::value_type> Compare>
|
||||
// requires CopyConstructible<Compare>
|
||||
// Iter
|
||||
// constexpr bool // constexpr after C++17
|
||||
// is_heap_until(Iter first, Iter last, Compare comp);
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
#if TEST_STD_VER > 17
|
||||
TEST_CONSTEXPR int test_constexpr() {
|
||||
int ia[] = {1, 0, 0, 0};
|
||||
int ib[] = {0, 1, 1, 0};
|
||||
return (std::is_heap_until(std::begin(ia), std::end(ia), std::greater<int>()) == ia+1)
|
||||
&& (std::is_heap_until(std::begin(ib), std::end(ib), std::greater<int>()) == ib+3);
|
||||
}
|
||||
#endif
|
||||
|
||||
void test()
|
||||
{
|
||||
int i1[] = {0, 0};
|
||||
@@ -519,4 +530,8 @@ void test()
|
||||
int main()
|
||||
{
|
||||
test();
|
||||
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test_constexpr());
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user