Implement P0548: 'common_type and duration' This involves a subtle change in the return type of the unary +/- operators for std::chrono::duration, though I expect that no one will notice.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@298416 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -37,6 +37,12 @@ namespace std
|
||||
typedef S<T> type;
|
||||
};
|
||||
|
||||
// P0548
|
||||
template <class T>
|
||||
struct common_type< ::S<T>, ::S<T> > {
|
||||
typedef S<T> type;
|
||||
};
|
||||
|
||||
template <> struct common_type< ::S<long>, long> {};
|
||||
template <> struct common_type<long, ::S<long> > {};
|
||||
}
|
||||
@@ -284,4 +290,19 @@ int main()
|
||||
test_bullet_three_two();
|
||||
test_bullet_four();
|
||||
#endif
|
||||
|
||||
// P0548
|
||||
static_assert((std::is_same<std::common_type<S<int> >::type, S<int> >::value), "");
|
||||
static_assert((std::is_same<std::common_type<S<int>, S<int> >::type, S<int> >::value), "");
|
||||
|
||||
static_assert((std::is_same<std::common_type<int>::type, int>::value), "");
|
||||
static_assert((std::is_same<std::common_type<const int>::type, int>::value), "");
|
||||
static_assert((std::is_same<std::common_type<volatile int>::type, int>::value), "");
|
||||
static_assert((std::is_same<std::common_type<const volatile int>::type, int>::value), "");
|
||||
|
||||
static_assert((std::is_same<std::common_type<int, int>::type, int>::value), "");
|
||||
static_assert((std::is_same<std::common_type<const int, int>::type, int>::value), "");
|
||||
static_assert((std::is_same<std::common_type<int, const int>::type, int>::value), "");
|
||||
static_assert((std::is_same<std::common_type<const int, const int>::type, int>::value), "");
|
||||
|
||||
}
|
||||
|
||||
@@ -11,11 +11,13 @@
|
||||
|
||||
// duration
|
||||
|
||||
// duration operator+() const;
|
||||
// constexpr common_type_t<duration> operator+() const;
|
||||
|
||||
#include <chrono>
|
||||
#include <cassert>
|
||||
|
||||
#include <test_macros.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
@@ -23,7 +25,7 @@ int main()
|
||||
std::chrono::minutes m2 = +m;
|
||||
assert(m.count() == m2.count());
|
||||
}
|
||||
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
constexpr std::chrono::minutes m(3);
|
||||
constexpr std::chrono::minutes m2 = +m;
|
||||
|
||||
@@ -11,11 +11,13 @@
|
||||
|
||||
// duration
|
||||
|
||||
// duration operator-() const;
|
||||
// constexpr common_type_t<duration> operator-() const;
|
||||
|
||||
#include <chrono>
|
||||
#include <cassert>
|
||||
|
||||
#include <test_macros.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
@@ -23,11 +25,23 @@ int main()
|
||||
std::chrono::minutes m2 = -m;
|
||||
assert(m2.count() == -m.count());
|
||||
}
|
||||
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
constexpr std::chrono::minutes m(3);
|
||||
constexpr std::chrono::minutes m2 = -m;
|
||||
static_assert(m2.count() == -m.count(), "");
|
||||
}
|
||||
#endif
|
||||
|
||||
// P0548
|
||||
{
|
||||
typedef std::chrono::duration<int, std::ratio<10,10> > D10;
|
||||
typedef std::chrono::duration<int, std::ratio< 1, 1> > D1;
|
||||
D10 zero{0};
|
||||
D10 one{1};
|
||||
static_assert( (std::is_same< decltype(-one), decltype(zero-one) >::value), "");
|
||||
static_assert( (std::is_same< decltype(zero-one), D1>::value), "");
|
||||
static_assert( (std::is_same< decltype(-one), D1>::value), "");
|
||||
static_assert( (std::is_same< decltype(+one), D1>::value), "");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user