forked from OSchip/llvm-project
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.
llvm-svn: 298416
This commit is contained in:
parent
0190698dd3
commit
9bd9ed4d23
|
@ -48,7 +48,7 @@ class duration
|
|||
static_assert(Period::num > 0, "duration period must be positive");
|
||||
public:
|
||||
typedef Rep rep;
|
||||
typedef Period period;
|
||||
typedef typename _Period::type period;
|
||||
|
||||
constexpr duration() = default;
|
||||
template <class Rep2>
|
||||
|
@ -75,8 +75,8 @@ public:
|
|||
|
||||
// arithmetic
|
||||
|
||||
constexpr duration operator+() const;
|
||||
constexpr duration operator-() const;
|
||||
constexpr common_type<duration>::type operator+() const;
|
||||
constexpr common_type<duration>::type operator-() const;
|
||||
constexpr duration& operator++();
|
||||
constexpr duration operator++(int);
|
||||
constexpr duration& operator--();
|
||||
|
@ -523,7 +523,7 @@ class _LIBCPP_TEMPLATE_VIS duration
|
|||
|
||||
public:
|
||||
typedef _Rep rep;
|
||||
typedef _Period period;
|
||||
typedef typename _Period::type period;
|
||||
private:
|
||||
rep __rep_;
|
||||
public:
|
||||
|
@ -565,8 +565,8 @@ public:
|
|||
|
||||
// arithmetic
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator+() const {return *this;}
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator-() const {return duration(-__rep_);}
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);}
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator-() const {return typename common_type<duration>::type(-__rep_);}
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator++() {++__rep_; return *this;}
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator++(int) {return duration(__rep_++);}
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator--() {--__rep_; return *this;}
|
||||
|
|
|
@ -1958,7 +1958,7 @@ template <class _Tp>
|
|||
struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, void, void>
|
||||
{
|
||||
public:
|
||||
typedef typename decay<_Tp>::type type;
|
||||
typedef typename common_type<_Tp, _Tp>::type type;
|
||||
};
|
||||
|
||||
template <class _Tp, class _Up>
|
||||
|
@ -1981,7 +1981,7 @@ struct _LIBCPP_TEMPLATE_VIS common_type {};
|
|||
template <class _Tp>
|
||||
struct _LIBCPP_TEMPLATE_VIS common_type<_Tp>
|
||||
{
|
||||
typedef typename decay<_Tp>::type type;
|
||||
typedef typename common_type<_Tp, _Tp>::type type;
|
||||
};
|
||||
|
||||
// bullet 3 - sizeof...(Tp) == 2
|
||||
|
|
|
@ -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), "");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -153,7 +153,7 @@
|
|||
<tr><td><a href="http://wg21.link/P0492R2">P0492R2</a></td><td>LWG</td><td>Proposed Resolution of C++17 National Body Comments for Filesystems</td><td>Kona</td><td></td><td></td></tr>
|
||||
<tr><td><a href="http://wg21.link/P0518R1">P0518R1</a></td><td>LWG</td><td>Allowing copies as arguments to function objects given to parallel algorithms in response to CH11</td><td>Kona</td><td></td><td></td></tr>
|
||||
<tr><td><a href="http://wg21.link/P0523R1">P0523R1</a></td><td>LWG</td><td>Wording for CH 10: Complexity of parallel algorithms</td><td>Kona</td><td></td><td></td></tr>
|
||||
<tr><td><a href="http://wg21.link/P0548R1">P0548R1</a></td><td>LWG</td><td>common_type and duration</td><td>Kona</td><td></td><td></td></tr>
|
||||
<tr><td><a href="http://wg21.link/P0548R1">P0548R1</a></td><td>LWG</td><td>common_type and duration</td><td>Kona</td><td>Complete</td><td>5.0</td></tr>
|
||||
<tr><td><a href="http://wg21.link/P0558R1">P0558R1</a></td><td>LWG</td><td>Resolving atomic<T> named base class inconsistencies</td><td>Kona</td><td></td><td></td></tr>
|
||||
<tr><td><a href="http://wg21.link/P0574R1">P0574R1</a></td><td>LWG</td><td>Algorithm Complexity Constraints and Parallel Overloads</td><td>Kona</td><td></td><td></td></tr>
|
||||
<tr><td><a href="http://wg21.link/P0599R1">P0599R1</a></td><td>LWG</td><td>noexcept for hash functions</td><td>Kona</td><td></td><td></td></tr>
|
||||
|
|
Loading…
Reference in New Issue