chrono (duration<>::operator%=, operator%): Add, per DR 934.
2009-07-21 Paolo Carlini <paolo.carlini@oracle.com> * include/std/chrono (duration<>::operator%=, operator%): Add, per DR 934. * testsuite/20_util/duration/arithmetic/dr934-1.cc: New. * testsuite/20_util/duration/arithmetic/dr934-2.cc: Likewise. * include/std/chrono (operator/): Simplify implementation. From-SVN: r149856
This commit is contained in:
parent
a1516d0836
commit
513c5a5bd9
|
@ -1,3 +1,12 @@
|
||||||
|
2009-07-21 Paolo Carlini <paolo.carlini@oracle.com>
|
||||||
|
|
||||||
|
* include/std/chrono (duration<>::operator%=, operator%):
|
||||||
|
Add, per DR 934.
|
||||||
|
* testsuite/20_util/duration/arithmetic/dr934-1.cc: New.
|
||||||
|
* testsuite/20_util/duration/arithmetic/dr934-2.cc: Likewise.
|
||||||
|
|
||||||
|
* include/std/chrono (operator/): Simplify implementation.
|
||||||
|
|
||||||
2009-07-20 Benjamin Kosnik <bkoz@redhat.com>
|
2009-07-20 Benjamin Kosnik <bkoz@redhat.com>
|
||||||
|
|
||||||
* doc/xml/manual/intro.xml: Escape '&', validate.
|
* doc/xml/manual/intro.xml: Escape '&', validate.
|
||||||
|
|
|
@ -211,7 +211,7 @@ namespace std
|
||||||
duration() = default;
|
duration() = default;
|
||||||
|
|
||||||
template<typename _Rep2>
|
template<typename _Rep2>
|
||||||
explicit duration(_Rep2 const& __rep)
|
explicit duration(const _Rep2& __rep)
|
||||||
: __r(static_cast<rep>(__rep))
|
: __r(static_cast<rep>(__rep))
|
||||||
{
|
{
|
||||||
static_assert(is_convertible<_Rep2,rep>::value
|
static_assert(is_convertible<_Rep2,rep>::value
|
||||||
|
@ -297,6 +297,25 @@ namespace std
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DR 934.
|
||||||
|
template<typename _Rep2 = rep>
|
||||||
|
typename enable_if<!treat_as_floating_point<_Rep2>::value,
|
||||||
|
duration&>::type
|
||||||
|
operator%=(const rep& __rhs)
|
||||||
|
{
|
||||||
|
__r %= __rhs;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename _Rep2 = rep>
|
||||||
|
typename enable_if<!treat_as_floating_point<_Rep2>::value,
|
||||||
|
duration&>::type
|
||||||
|
operator%=(const duration& __d)
|
||||||
|
{
|
||||||
|
__r %= __d.count();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
// 20.8.3.4 special values
|
// 20.8.3.4 special values
|
||||||
// TODO: These should be constexprs.
|
// TODO: These should be constexprs.
|
||||||
static const duration
|
static const duration
|
||||||
|
@ -352,43 +371,46 @@ namespace std
|
||||||
operator*(const _Rep2& __s, const duration<_Rep1, _Period>& __d)
|
operator*(const _Rep2& __s, const duration<_Rep1, _Period>& __d)
|
||||||
{ return __d * __s; }
|
{ return __d * __s; }
|
||||||
|
|
||||||
template<typename _Tp, typename _Up, typename _Ep = void>
|
|
||||||
struct __division_impl;
|
|
||||||
|
|
||||||
template<typename _Rep1, typename _Period, typename _Rep2>
|
template<typename _Rep1, typename _Period, typename _Rep2>
|
||||||
struct __division_impl<duration<_Rep1, _Period>, _Rep2,
|
inline duration<typename common_type<_Rep1, typename
|
||||||
typename enable_if<!__is_duration<_Rep2>::value>::type>
|
enable_if<!__is_duration<_Rep2>::value, _Rep2>::type>::type, _Period>
|
||||||
|
operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
|
||||||
{
|
{
|
||||||
typedef typename common_type<_Rep1, _Rep2>::type __cr;
|
typedef typename common_type<_Rep1, _Rep2>::type __cr;
|
||||||
typedef
|
return duration<__cr, _Period>(__d) /= __s;
|
||||||
duration<typename common_type<_Rep1, _Rep2>::type, _Period> __rt;
|
}
|
||||||
|
|
||||||
static __rt
|
template<typename _Rep1, typename _Period1,
|
||||||
__divide(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
|
typename _Rep2, typename _Period2>
|
||||||
{ return duration<__cr, _Period>(__d) /= __s; }
|
inline typename common_type<_Rep1, _Rep2>::type
|
||||||
};
|
operator/(const duration<_Rep1, _Period1>& __lhs,
|
||||||
|
const duration<_Rep2, _Period2>& __rhs)
|
||||||
template<typename _Rep1, typename _Period1,
|
|
||||||
typename _Rep2, typename _Period2>
|
|
||||||
struct __division_impl<duration<_Rep1, _Period1>,
|
|
||||||
duration<_Rep2, _Period2>>
|
|
||||||
{
|
{
|
||||||
typedef typename common_type<duration<_Rep1, _Period1>,
|
typedef typename common_type<duration<_Rep1, _Period1>,
|
||||||
duration<_Rep2, _Period2>>::type __ct;
|
duration<_Rep2, _Period2>>::type __ct;
|
||||||
typedef typename common_type<_Rep1, _Rep2>::type __rt;
|
return __ct(__lhs).count() / __ct(__rhs).count();
|
||||||
|
}
|
||||||
|
|
||||||
static __rt
|
// DR 934.
|
||||||
__divide(const duration<_Rep1, _Period1>& __lhs,
|
template<typename _Rep1, typename _Period, typename _Rep2>
|
||||||
const duration<_Rep2, _Period2>& __rhs)
|
inline duration<typename common_type<_Rep1, typename
|
||||||
{ return __ct(__lhs).count() / __ct(__rhs).count(); }
|
enable_if<!__is_duration<_Rep2>::value, _Rep2>::type>::type, _Period>
|
||||||
};
|
operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
|
||||||
|
|
||||||
template<typename _Rep, typename _Period, typename _Up>
|
|
||||||
inline typename __division_impl<duration<_Rep, _Period>, _Up>::__rt
|
|
||||||
operator/(const duration<_Rep, _Period>& __d, const _Up& __u)
|
|
||||||
{
|
{
|
||||||
return
|
typedef typename common_type<_Rep1, _Rep2>::type __cr;
|
||||||
__division_impl<duration<_Rep, _Period>, _Up>::__divide(__d, __u);
|
return duration<__cr, _Period>(__d) %= __s;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename _Rep1, typename _Period1,
|
||||||
|
typename _Rep2, typename _Period2>
|
||||||
|
inline typename common_type<duration<_Rep1, _Period1>,
|
||||||
|
duration<_Rep2, _Period2>>::type
|
||||||
|
operator%(const duration<_Rep1, _Period1>& __lhs,
|
||||||
|
const duration<_Rep2, _Period2>& __rhs)
|
||||||
|
{
|
||||||
|
typedef typename common_type<duration<_Rep1, _Period1>,
|
||||||
|
duration<_Rep2, _Period2>>::type __ct;
|
||||||
|
return __ct(__lhs) %= __rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
// comparisons
|
// comparisons
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
// { dg-do compile }
|
||||||
|
// { dg-options "-std=gnu++0x" }
|
||||||
|
// { dg-require-cstdint "" }
|
||||||
|
|
||||||
|
// Copyright (C) 2009 Free Software Foundation
|
||||||
|
//
|
||||||
|
// This file is part of the GNU ISO C++ Library. This library is free
|
||||||
|
// software; you can redistribute it and/or modify it under the
|
||||||
|
// terms of the GNU General Public License as published by the
|
||||||
|
// Free Software Foundation; either version 3, or (at your option)
|
||||||
|
// any later version.
|
||||||
|
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU General Public License along
|
||||||
|
// with this library; see the file COPYING3. If not see
|
||||||
|
// <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
class ClockTime
|
||||||
|
{
|
||||||
|
typedef std::chrono::hours hours;
|
||||||
|
typedef std::chrono::minutes minutes;
|
||||||
|
typedef std::chrono::seconds seconds;
|
||||||
|
|
||||||
|
public:
|
||||||
|
hours hours_;
|
||||||
|
minutes minutes_;
|
||||||
|
seconds seconds_;
|
||||||
|
|
||||||
|
template<typename Rep, typename Period>
|
||||||
|
explicit
|
||||||
|
ClockTime(const std::chrono::duration<Rep, Period>& d)
|
||||||
|
: hours_ (std::chrono::duration_cast<hours> (d)),
|
||||||
|
minutes_(std::chrono::duration_cast<minutes>(d % hours(1))),
|
||||||
|
seconds_(std::chrono::duration_cast<seconds>(d % minutes(1))) { }
|
||||||
|
};
|
||||||
|
|
||||||
|
// DR 934.
|
||||||
|
void test01()
|
||||||
|
{
|
||||||
|
std::chrono::duration<int> d;
|
||||||
|
ClockTime ct(d);
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
// { dg-options "-std=gnu++0x" }
|
||||||
|
// { dg-require-cstdint "" }
|
||||||
|
|
||||||
|
// Copyright (C) 2009 Free Software Foundation
|
||||||
|
//
|
||||||
|
// This file is part of the GNU ISO C++ Library. This library is free
|
||||||
|
// software; you can redistribute it and/or modify it under the
|
||||||
|
// terms of the GNU General Public License as published by the
|
||||||
|
// Free Software Foundation; either version 3, or (at your option)
|
||||||
|
// any later version.
|
||||||
|
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU General Public License along
|
||||||
|
// with this library; see the file COPYING3. If not see
|
||||||
|
// <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <testsuite_hooks.h>
|
||||||
|
|
||||||
|
// DR 934.
|
||||||
|
void
|
||||||
|
test01()
|
||||||
|
{
|
||||||
|
bool test __attribute__((unused)) = true;
|
||||||
|
using namespace std::chrono;
|
||||||
|
|
||||||
|
const duration<int> d0(17);
|
||||||
|
duration<int> d3(d0);
|
||||||
|
d3 %= 5;
|
||||||
|
VERIFY( d3.count() == 2 );
|
||||||
|
|
||||||
|
const duration<int> d4(7);
|
||||||
|
duration<int> d5(d0);
|
||||||
|
d5 %= d4;
|
||||||
|
VERIFY( d5.count() == 3 );
|
||||||
|
|
||||||
|
const duration<int> d6 = d0 % 6;
|
||||||
|
VERIFY( d6.count() == 5 );
|
||||||
|
|
||||||
|
const duration<int> d7(11);
|
||||||
|
const duration<int> d8 = d0 % d7;
|
||||||
|
VERIFY( d8.count() == 6 );
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
test01();
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue