Implement P0505: 'Wording for GB 50'

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@291028 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow
2017-01-04 23:03:24 +00:00
parent 9c6b70a0af
commit 3df90c94a3
12 changed files with 207 additions and 33 deletions

View File

@@ -11,15 +11,31 @@
// duration
// duration& operator++();
// constexpr duration& operator++(); // constexpr in c++17
#include <chrono>
#include <cassert>
#include "test_macros.h"
#if TEST_STD_VER > 14
constexpr bool test_constexpr()
{
std::chrono::hours h(3);
return (++h).count() == 4;
}
#endif
int main()
{
{
std::chrono::hours h(3);
std::chrono::hours& href = ++h;
assert(&href == &h);
assert(h.count() == 4);
}
#if TEST_STD_VER > 14
static_assert(test_constexpr(), "");
#endif
}

View File

@@ -11,15 +11,32 @@
// duration
// duration operator++(int);
// constexpr duration operator++(int); // constexpr in c++17
#include <chrono>
#include <cassert>
#include "test_macros.h"
#if TEST_STD_VER > 14
constexpr bool test_constexpr()
{
std::chrono::hours h1(3);
std::chrono::hours h2 = h1++;
return h1.count() == 4 && h2.count() == 3;
}
#endif
int main()
{
std::chrono::hours h(3);
std::chrono::hours h2 = h++;
assert(h.count() == 4);
{
std::chrono::hours h1(3);
std::chrono::hours h2 = h1++;
assert(h1.count() == 4);
assert(h2.count() == 3);
}
#if TEST_STD_VER > 14
static_assert(test_constexpr(), "");
#endif
}

View File

@@ -11,16 +11,35 @@
// duration
// duration& operator+=(const duration& d);
// constexpr duration& operator+=(const duration& d); // constexpr in c++17
#include <chrono>
#include <cassert>
#include "test_macros.h"
#if TEST_STD_VER > 14
constexpr bool test_constexpr()
{
std::chrono::seconds s(3);
s += std::chrono::seconds(2);
if (s.count() != 5) return false;
s += std::chrono::minutes(2);
return s.count() == 125;
}
#endif
int main()
{
{
std::chrono::seconds s(3);
s += std::chrono::seconds(2);
assert(s.count() == 5);
s += std::chrono::minutes(2);
assert(s.count() == 125);
}
#if TEST_STD_VER > 14
static_assert(test_constexpr(), "");
#endif
}

View File

@@ -11,15 +11,31 @@
// duration
// duration& operator--();
// constexpr duration& operator--(); // constexpr in C++17
#include <chrono>
#include <cassert>
#include "test_macros.h"
#if TEST_STD_VER > 14
constexpr bool test_constexpr()
{
std::chrono::hours h(3);
return (--h).count() == 2;
}
#endif
int main()
{
{
std::chrono::hours h(3);
std::chrono::hours& href = --h;
assert(&href == &h);
assert(h.count() == 2);
}
#if TEST_STD_VER > 14
static_assert(test_constexpr(), "");
#endif
}

View File

@@ -11,15 +11,33 @@
// duration
// duration operator--(int);
// constexpr duration operator--(int); // constexpr in C++17
#include <chrono>
#include <cassert>
#include "test_macros.h"
#if TEST_STD_VER > 14
constexpr bool test_constexpr()
{
std::chrono::hours h1(3);
std::chrono::hours h2 = h1--;
return h1.count() == 2 && h2.count() == 3;
}
#endif
int main()
{
std::chrono::hours h(3);
std::chrono::hours h2 = h--;
assert(h.count() == 2);
{
std::chrono::hours h1(3);
std::chrono::hours h2 = h1--;
assert(h1.count() == 2);
assert(h2.count() == 3);
}
#if TEST_STD_VER > 14
static_assert(test_constexpr(), "");
#endif
}

View File

@@ -16,11 +16,30 @@
#include <chrono>
#include <cassert>
#include "test_macros.h"
#if TEST_STD_VER > 14
constexpr bool test_constexpr()
{
std::chrono::seconds s(3);
s -= std::chrono::seconds(2);
if (s.count() != 1) return false;
s -= std::chrono::minutes(2);
return s.count() == -119;
}
#endif
int main()
{
{
std::chrono::seconds s(3);
s -= std::chrono::seconds(2);
assert(s.count() == 1);
s -= std::chrono::minutes(2);
assert(s.count() == -119);
}
#if TEST_STD_VER > 14
static_assert(test_constexpr(), "");
#endif
}

View File

@@ -16,9 +16,26 @@
#include <chrono>
#include <cassert>
#include "test_macros.h"
#if TEST_STD_VER > 14
constexpr bool test_constexpr()
{
std::chrono::seconds s(15);
s /= 5;
return s.count() == 3;
}
#endif
int main()
{
{
std::chrono::nanoseconds ns(15);
ns /= 5;
assert(ns.count() == 3);
}
#if TEST_STD_VER > 14
static_assert(test_constexpr(), "");
#endif
}

View File

@@ -16,12 +16,30 @@
#include <chrono>
#include <cassert>
#include "test_macros.h"
#if TEST_STD_VER > 14
constexpr bool test_constexpr()
{
std::chrono::microseconds us1(11);
std::chrono::microseconds us2(3);
us1 %= us2;
return us1.count() == 2;
}
#endif
int main()
{
std::chrono::microseconds us(11);
{
std::chrono::microseconds us1(11);
std::chrono::microseconds us2(3);
us %= us2;
assert(us.count() == 2);
us %= std::chrono::milliseconds(3);
assert(us.count() == 2);
us1 %= us2;
assert(us1.count() == 2);
us1 %= std::chrono::milliseconds(3);
assert(us1.count() == 2);
}
#if TEST_STD_VER > 14
static_assert(test_constexpr(), "");
#endif
}

View File

@@ -16,9 +16,26 @@
#include <chrono>
#include <cassert>
#include "test_macros.h"
#if TEST_STD_VER > 14
constexpr bool test_constexpr()
{
std::chrono::seconds s(11);
s %= 3;
return s.count() == 2;
}
#endif
int main()
{
{
std::chrono::microseconds us(11);
us %= 3;
assert(us.count() == 2);
}
#if TEST_STD_VER > 14
static_assert(test_constexpr(), "");
#endif
}

View File

@@ -16,9 +16,26 @@
#include <chrono>
#include <cassert>
#include "test_macros.h"
#if TEST_STD_VER > 14
constexpr bool test_constexpr()
{
std::chrono::seconds s(3);
s *= 5;
return s.count() == 15;
}
#endif
int main()
{
{
std::chrono::nanoseconds ns(3);
ns *= 5;
assert(ns.count() == 15);
}
#if TEST_STD_VER > 14
static_assert(test_constexpr(), "");
#endif
}