Commit 15e38d0d by Chris Fairles Committed by Paolo Carlini

chrono: New, as per N2661.

2008-07-15  Chris Fairles  <chris.fairles@gmail.com>

        * include/std/chrono: New, as per N2661.
        * src/chrono.cc: New.
        * include/Makefile.am: Update.
        * src/Makefile.am: Likewise.
        * include/Makefile.in: Regenerate.
        * src/Makefile.in: Likewise.
        * acinclude.m4: Add tests for clock_gettime and gettimeofday that
	define _GLIBCXX_HAS_CLOCK_GETTIME and/or _GLIBCXX_HAS_GETTIMEOFDAY.
        * configure.ac: Use them.
        * configure: Regenerate.
        * config.h.in: Likewise.
        * config/abi/pre/gnu.ver: Add symbols for system_clock::now() and
        system_clock::is_monotonic.
        * testsuite/20_util/duration/cons/1.cc: New.
        * testsuite/20_util/duration/cons/2.cc: Likewise.
        * testsuite/20_util/duration/cons/1_neg.cc: Likewise.
        * testsuite/20_util/duration/requirements/explicit_instantiation/
        explicit_instantiation.cc: Likewise.
        * testsuite/20_util/duration/arithmetic/1.cc: Likewise.
        * testsuite/20_util/duration/arithmetic/2.cc: Likewise.
        * testsuite/20_util/duration/comparisons/1.cc: Likewise.
        * testsuite/20_util/time_point/requirements/explicit_instantiation/
        explicit_instantiation.cc: Likewise.
        * testsuite/20_util/time_point/1.cc: Likewise.
        * testsuite/20_util/time_point/2.cc: Likewise.
        * testsuite/20_util/time_point/3.cc: Likewise.
        * testsuite/20_util/clocks/1.cc: Likewise.
        * testsuite/17_intro/headers/c++200x/all_multiple_inclusion.cc: Add
        missing headers.
        * testsuite/17_intro/headers/c++200x/all.cc: Likewise.
        * include/precompiled/stdc++.h: Likewise and remove <date_time>.
        * doc/doxygen/user.cfg.in: Likewise.

From-SVN: r137858
parent 141368f0
2008-07-15 Chris Fairles <chris.fairles@gmail.com>
* include/std/chrono: New, as per N2661.
* src/chrono.cc: New.
* include/Makefile.am: Update.
* src/Makefile.am: Likewise.
* include/Makefile.in: Regenerate.
* src/Makefile.in: Likewise.
* acinclude.m4: Add tests for clock_gettime and gettimeofday that
define _GLIBCXX_HAS_CLOCK_GETTIME and/or _GLIBCXX_HAS_GETTIMEOFDAY.
* configure.ac: Use them.
* configure: Regenerate.
* config.h.in: Likewise.
* config/abi/pre/gnu.ver: Add symbols for system_clock::now() and
system_clock::is_monotonic.
* testsuite/20_util/duration/cons/1.cc: New.
* testsuite/20_util/duration/cons/2.cc: Likewise.
* testsuite/20_util/duration/cons/1_neg.cc: Likewise.
* testsuite/20_util/duration/requirements/explicit_instantiation/
explicit_instantiation.cc: Likewise.
* testsuite/20_util/duration/arithmetic/1.cc: Likewise.
* testsuite/20_util/duration/arithmetic/2.cc: Likewise.
* testsuite/20_util/duration/comparisons/1.cc: Likewise.
* testsuite/20_util/time_point/requirements/explicit_instantiation/
explicit_instantiation.cc: Likewise.
* testsuite/20_util/time_point/1.cc: Likewise.
* testsuite/20_util/time_point/2.cc: Likewise.
* testsuite/20_util/time_point/3.cc: Likewise.
* testsuite/20_util/clocks/1.cc: Likewise.
* testsuite/17_intro/headers/c++200x/all_multiple_inclusion.cc: Add
missing headers.
* testsuite/17_intro/headers/c++200x/all.cc: Likewise.
* include/precompiled/stdc++.h: Likewise and remove <date_time>.
* doc/doxygen/user.cfg.in: Likewise.
2008-07-15 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/36832
......
......@@ -1009,6 +1009,94 @@ AC_DEFUN([GLIBCXX_ENABLE_C99], [
dnl
dnl Check for IEEE Std 1003.1-2001 clock_gettime required for
dnl 20.8.5 [time.clock] in the current C++0X working draft.
dnl
AC_DEFUN([GLIBCXX_CHECK_CLOCK_GETTIME], [
AC_LANG_SAVE
AC_LANG_CPLUSPLUS
ac_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -fno-exceptions"
AC_CHECK_HEADERS(unistd.h, ac_has_unistd_h=yes, ac_has_unistd_h=no)
ac_has_clock_monotonic=no;
ac_has_clock_realtime=no;
if test x"$ac_has_unistd_h" = x"yes"; then
AC_MSG_CHECKING([for monotonic clock])
AC_TRY_LINK(
[#include <unistd.h>
#include <time.h>
],
[#if _POSIX_TIMERS > 0 && defined(_POSIX_MONOTONIC_CLOCK)
timespec tp;
#endif
clock_gettime(CLOCK_MONOTONIC, &tp);
], [ac_has_clock_monotonic=yes], [ac_has_clock_monotonic=no])
AC_MSG_RESULT($ac_has_clock_monotonic)
AC_MSG_CHECKING([for realtime clock])
AC_TRY_LINK(
[#include <unistd.h>
#include <time.h>
],
[#if _POSIX_TIMERS > 0
timespec tp;
#endif
clock_gettime(CLOCK_REALTIME, &tp);
], [ac_has_clock_realtime=yes], [ac_has_clock_realtime=no])
AC_MSG_RESULT($ac_has_clock_realtime)
fi
if test x"$ac_has_clock_monotonic" = x"yes"; then
AC_DEFINE(_GLIBCXX_USE_CLOCK_MONOTONIC, 1,
[ Defined if clock_gettime has monotonic clock support. ])
fi
if test x"$ac_has_clock_realtime" = x"yes"; then
AC_DEFINE(_GLIBCXX_USE_CLOCK_REALTIME, 1,
[ Defined if clock_gettime has realtime clock support. ])
fi
CXXFLAGS="$ac_save_CXXFLAGS"
AC_LANG_RESTORE
])
dnl
dnl Check for IEEE Std 1003.1-2001 gettimeofday required for
dnl 20.8.5 [time.clock] in the current C++0X working draft.
dnl
AC_DEFUN([GLIBCXX_CHECK_GETTIMEOFDAY], [
AC_LANG_SAVE
AC_LANG_CPLUSPLUS
ac_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -fno-exceptions"
ac_has_gettimeofday=no;
AC_CHECK_HEADERS(sys/time.h, ac_has_sys_time_h=yes, ac_has_sys_time_h=no)
if test x"$ac_has_sys_time_h" = x"yes"; then
AC_MSG_CHECKING([for gettimeofday])
AC_TRY_LINK([#include <sys/time.h>],
[timeval tv; gettimeofday(&tv, 0);],
[ac_has_gettimeofday=yes], [ac_has_gettimeofday=no])
AC_MSG_RESULT($ac_has_gettimeofday)
fi
if test x"$ac_has_gettimeofday" = x"yes"; then
AC_DEFINE(_GLIBCXX_USE_GETTIMEOFDAY, 1,
[ Defined if gettimeofday is available. ])
fi
CXXFLAGS="$ac_save_CXXFLAGS"
AC_LANG_RESTORE
])
dnl
dnl Check for ISO/IEC 9899:1999 "C99" support to ISO/IEC DTR 19768 "TR1"
dnl facilities in Chapter 8, "C compatibility".
dnl
......
......@@ -811,6 +811,15 @@
namespace std::tr1. */
#undef _GLIBCXX_USE_C99_STDINT_TR1
/* Defined if clock_gettime has monotonic clock support. */
#undef _GLIBCXX_USE_CLOCK_MONOTONIC
/* Defined if clock_gettime has realtime clock support. */
#undef _GLIBCXX_USE_CLOCK_REALTIME
/* Defined if gettimeofday is available. */
#undef _GLIBCXX_USE_GETTIMEOFDAY
/* Define if LFS support is available. */
#undef _GLIBCXX_USE_LFS
......
......@@ -885,6 +885,10 @@ GLIBCXX_3.4.11 {
# char16_t and char32_t
_ZNSt14numeric_limitsIu8char*;
# chrono
_ZNSt6chrono12system_clock12is_monotonicE;
_ZNSt6chrono12system_clock3nowEv;
} GLIBCXX_3.4.10;
# Symbols in the support library (libsupc++) have their own tag.
......
......@@ -161,6 +161,12 @@ if $GLIBCXX_IS_NATIVE; then
# For dev/random and dev/urandom for TR1.
GLIBCXX_CHECK_RANDOM_TR1
# For clock_gettime support.
GLIBCXX_CHECK_CLOCK_GETTIME
# For gettimeofday support.
GLIBCXX_CHECK_GETTIMEOFDAY
# For TLS support.
GCC_CHECK_TLS
......
......@@ -468,8 +468,8 @@ INPUT = @srcdir@/libsupc++/cxxabi.h \
include/algorithm \
include/array \
include/bitset \
include/chrono \
include/condition_variable \
include/date_time \
include/deque \
include/fstream \
include/functional \
......@@ -489,6 +489,7 @@ INPUT = @srcdir@/libsupc++/cxxabi.h \
include/ostream \
include/queue \
include/random \
include/ratio \
include/regex \
include/set \
include/sstream \
......
......@@ -32,6 +32,7 @@ std_headers = \
${std_srcdir}/array \
${std_srcdir}/bitset \
${std_srcdir}/c++0x_warning.h \
${std_srcdir}/chrono \
${std_srcdir}/complex \
${std_srcdir}/condition_variable \
${std_srcdir}/deque \
......
......@@ -285,6 +285,7 @@ std_headers = \
${std_srcdir}/array \
${std_srcdir}/bitset \
${std_srcdir}/c++0x_warning.h \
${std_srcdir}/chrono \
${std_srcdir}/complex \
${std_srcdir}/condition_variable \
${std_srcdir}/deque \
......
......@@ -98,8 +98,9 @@
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <date_time>
#include <chrono>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <tuple>
......
......@@ -186,6 +186,7 @@ sources = \
wstring-inst.cc \
mutex.cc \
condition_variable.cc \
chrono.cc \
${host_sources} \
${host_sources_extra}
......@@ -272,6 +273,11 @@ atomic.lo: atomic.cc
atomic.o: atomic.cc
$(CXXCOMPILE) -x c++ -std=gnu++0x -c $<
chrono.lo: chrono.cc
$(LTCXXCOMPILE) -std=gnu++0x -c $<
chrono.o: chrono.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
if GLIBCXX_LDBL_COMPAT
# Use special rules for compatibility-ldbl.cc compilation, as we need to
# pass -mlong-double-64.
......
......@@ -84,10 +84,10 @@ am__libstdc___la_SOURCES_DIST = atomic.cc bitmap_allocator.cc \
istream-inst.cc istream.cc locale-inst.cc misc-inst.cc \
ostream-inst.cc sstream-inst.cc streambuf-inst.cc streambuf.cc \
string-inst.cc valarray-inst.cc wlocale-inst.cc \
wstring-inst.cc mutex.cc condition_variable.cc atomicity.cc \
codecvt_members.cc collate_members.cc ctype_members.cc \
messages_members.cc monetary_members.cc numeric_members.cc \
time_members.cc basic_file.cc c++locale.cc \
wstring-inst.cc mutex.cc condition_variable.cc chrono.cc \
atomicity.cc codecvt_members.cc collate_members.cc \
ctype_members.cc messages_members.cc monetary_members.cc \
numeric_members.cc time_members.cc basic_file.cc c++locale.cc \
compatibility-ldbl.cc parallel_list.cc parallel_settings.cc
am__objects_1 = atomicity.lo codecvt_members.lo collate_members.lo \
ctype_members.lo messages_members.lo monetary_members.lo \
......@@ -109,7 +109,7 @@ am__objects_5 = atomic.lo bitmap_allocator.lo pool_allocator.lo \
istream-inst.lo istream.lo locale-inst.lo misc-inst.lo \
ostream-inst.lo sstream-inst.lo streambuf-inst.lo streambuf.lo \
string-inst.lo valarray-inst.lo wlocale-inst.lo \
wstring-inst.lo mutex.lo condition_variable.lo \
wstring-inst.lo mutex.lo condition_variable.lo chrono.lo \
$(am__objects_1) $(am__objects_4)
am_libstdc___la_OBJECTS = $(am__objects_5)
libstdc___la_OBJECTS = $(am_libstdc___la_OBJECTS)
......@@ -422,6 +422,7 @@ sources = \
wstring-inst.cc \
mutex.cc \
condition_variable.cc \
chrono.cc \
${host_sources} \
${host_sources_extra}
......@@ -866,6 +867,11 @@ atomic.lo: atomic.cc
atomic.o: atomic.cc
$(CXXCOMPILE) -x c++ -std=gnu++0x -c $<
chrono.lo: chrono.cc
$(LTCXXCOMPILE) -std=gnu++0x -c $<
chrono.o: chrono.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
# Use special rules for compatibility-ldbl.cc compilation, as we need to
# pass -mlong-double-64.
@GLIBCXX_LDBL_COMPAT_TRUE@compatibility-ldbl.lo: compatibility-ldbl.cc
......
// chrono -*- C++ -*-
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <chrono>
#ifdef _GLIBCXX_USE_C99_STDINT_TR1
// conditional inclusion of sys/time.h for gettimeofday
#if !defined(_GLIBCXX_USE_CLOCK_MONOTONIC) && \
!defined(_GLIBCXX_USE_CLOCK_REALTIME) && \
defined(_GLIBCXX_USE_GETTIMEOFDAY)
#include <sys/time.h>
#endif
namespace std
{
namespace chrono
{
const bool system_clock::is_monotonic;
system_clock::time_point
system_clock::now()
{
#ifdef _GLIBCXX_USE_CLOCK_MONOTONIC
timespec tp;
// -EINVAL, -EFAULT
clock_gettime(CLOCK_MONOTONIC, &tp);
return time_point(duration(chrono::seconds(tp.tv_sec)
+ chrono::nanoseconds(tp.tv_nsec)));
#elif defined(_GLIBCXX_USE_CLOCK_REALTIME)
timespec tp;
// -EINVAL, -EFAULT
clock_gettime(CLOCK_REALTIME, &tp);
return time_point(duration(chrono::seconds(tp.tv_sec)
+ chrono::nanoseconds(tp.tv_nsec)));
#elif defined(_GLIBCXX_USE_GETTIMEOFDAY)
timeval tv;
// EINVAL, EFAULT
gettimeofday(&tv, NULL);
return time_point(duration(chrono::seconds(tv.tv_sec)
+ chrono::microseconds(tv.tv_usec)));
#else
std::time_t __sec = std::time(0);
return system_clock::from_time_t(__sec);
#endif
}
}
}
#endif // _GLIBCXX_USE_C99_STDINT_TR1
......@@ -95,6 +95,7 @@
#include <algorithm>
#include <array>
#include <bitset>
#include <chrono>
#include <condition_variable>
#include <complex>
#include <deque>
......@@ -118,6 +119,7 @@
#include <ostream>
#include <queue>
#include <random>
#include <ratio>
#include <regex>
#include <set>
#include <sstream>
......
......@@ -93,6 +93,7 @@
#include <algorithm>
#include <array>
#include <bitset>
#include <chrono>
#include <complex>
#include <deque>
#include <exception>
......@@ -114,6 +115,7 @@
#include <ostream>
#include <queue>
#include <random>
#include <ratio>
#include <regex>
#include <set>
#include <sstream>
......@@ -203,6 +205,7 @@
#include <algorithm>
#include <array>
#include <bitset>
#include <chrono>
#include <complex>
#include <deque>
#include <exception>
......@@ -219,11 +222,13 @@
#include <locale>
#include <map>
#include <memory>
#include <mutex>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <ratio>
#include <regex>
#include <set>
#include <sstream>
......
// { dg-options "-std=gnu++0x" }
// { dg-require-cstdint "" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 20.8.5 Clocks [time.clock]
#include <chrono>
// 20.8.5.1 system_clock [time.clock.system]
int
main()
{
using namespace std::chrono;
system_clock::time_point t1 = system_clock::now();
bool is_monotonic = system_clock::is_monotonic;
is_monotonic = is_monotonic; // suppress unused warning
std::time_t t2 = system_clock::to_time_t(t1);
system_clock::time_point t3 = system_clock::from_time_t(t2);
return 0;
}
// { dg-options "-std=gnu++0x" }
// { dg-require-cstdint "" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 20.8.3 Class template duration [time.duration]
#include <chrono>
#include <testsuite_hooks.h>
// 20.8.3.3 duration arithmetic [time.duration.arithmetic] (unary member ops)
void
test01()
{
bool test __attribute__((unused)) = true;
using namespace std::chrono;
duration<int> d0(3);
duration<int> d1 = -d0;
VERIFY(d0.count() == 3);
VERIFY(d1.count() == -3);
duration<int> d2 = (+d0);
VERIFY(d2.count() == 3);
duration<int> d3(++d2);
VERIFY(d2.count() == 4);
VERIFY(d3.count() == 4);
duration<int> d4(d3++);
VERIFY(d3.count() == 5);
VERIFY(d4.count() == 4);
duration<int> d5(--d4);
VERIFY(d4.count() == 3);
VERIFY(d5.count() == 3);
duration<int> d6(d5--);
VERIFY(d5.count() == 2);
VERIFY(d6.count() == 3);
}
// 20.8.3.3 duration arithmetic [time.duration.arithmetic] (binary member ops)
void
test02()
{
bool test __attribute__((unused)) = true;
using namespace std::chrono;
duration<int> d7(3);
duration<int> d8(9);
d7 += d8;
VERIFY(d7.count() == 12);
VERIFY(d8.count() == 9);
duration<int> d9(3);
duration<int> d10(9);
d9 -= d10;
VERIFY(d9.count() == -6);
VERIFY(d10.count() == 9);
duration<int> d11(9);
int i = 3;
d11 *= i;
VERIFY(d11.count() == 27);
duration<int> d12(12);
d12 /= i;
VERIFY(d12.count() == 4);
}
int
main()
{
test01();
test02();
return 0;
}
// { dg-options "-std=gnu++0x" }
// { dg-require-cstdint "" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 20.8.3 Class template duration [time.duration]
#include <chrono>
#include <testsuite_hooks.h>
// 20.8.3.5 duration non-member arithmetic [time.duration.nonmember]
void
test01()
{
bool test __attribute__((unused)) = true;
using namespace std::chrono;
duration<int> d0(12);
duration<int> d1(3);
int i = 3;
duration<int> d2 = d0 + d1;
VERIFY(d2.count() == 15);
duration<int> d3 = d0 - d1;
VERIFY(d3.count() == 9);
duration<int> d4 = d0 * i;
VERIFY(d4.count() == 36);
duration<int> d5 = i * d0;
VERIFY(d5.count() == 36);
duration<int> d6 = d0 / i;
VERIFY(d6.count() == 4);
int j = d0 / d1;
VERIFY(j == 4);
}
int
main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// { dg-require-cstdint "" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 20.8.3 Class template duration [time.duration]
#include <chrono>
#include <testsuite_hooks.h>
// 20.8.3.6 duration comparisons [time.duration.comparisons]
void
test01()
{
bool test __attribute__((unused)) = true;
using namespace std::chrono;
duration<int> d0(12);
duration<int> d1(3);
duration<int> d2(3);
VERIFY(d1 < d0);
VERIFY(d0 > d1);
VERIFY(d0 != d1);
VERIFY(d1 == d2);
VERIFY(d1 <= d2);
VERIFY(d1 >= d2);
VERIFY(d1 <= d0);
VERIFY(d0 >= d1);
}
int
main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// { dg-require-cstdint "" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 20.8.3 Class template duration [time.duration]
#include <chrono>
#include <type_traits>
#include <testsuite_hooks.h>
template<typename T>
struct type_emulator
{
type_emulator()
: i(T(0)) { }
type_emulator(T j)
: i(j) { }
type_emulator(const type_emulator& e)
: i(e.i) { }
type_emulator&
operator*=(type_emulator a)
{
i *= a.i;
return *this;
}
type_emulator&
operator+=(type_emulator a)
{
i += a.i;
return *this;
}
operator T ()
{ return i; }
T i;
};
template<typename T>
bool
operator==(type_emulator<T> a, type_emulator<T> b)
{ return a.i == b.i; }
template<typename T>
bool
operator<(type_emulator<T> a, type_emulator<T> b)
{ return a.i < b.i; }
template<typename T>
type_emulator<T>
operator+(type_emulator<T> a, type_emulator<T> b)
{ return a += b; }
template<typename T>
type_emulator<T>
operator*(type_emulator<T> a, type_emulator<T> b)
{ return a *= b; }
namespace std
{
template<typename T, typename U>
struct common_type<type_emulator<T>, U>
{ typedef typename common_type<T,U>::type type; };
template<typename T, typename U>
struct common_type<U, type_emulator<T>>
{ typedef typename common_type<U,T>::type type; };
template<typename T, typename U>
struct common_type<type_emulator<T>, type_emulator<U>>
{ typedef typename common_type<T,U>::type type; };
namespace chrono
{
template<typename T>
struct treat_as_floating_point<type_emulator<T>>
: is_floating_point<T>
{ };
}
}
typedef type_emulator<int> int_emulator;
typedef type_emulator<double> dbl_emulator;
// 20.8.3.1 duration constructors [time.duration.cons]
void
test01()
{
bool test __attribute__((unused)) = true;
using std::chrono::duration;
duration<int> d0;
VERIFY(d0.count() == static_cast<duration<int>::rep>(0));
int r = 3;
duration<int> d1(r);
VERIFY(d1.count() == static_cast<duration<int>::rep>(r));
double s = 8.0;
duration<double> d2(s);
VERIFY(d2.count() == static_cast<duration<double>::rep>(s));
int_emulator ie(3);
duration<int_emulator> d3(ie);
VERIFY(d3.count() == static_cast<duration<int_emulator>::rep>(ie));
dbl_emulator de(4.0);
duration<dbl_emulator> d4(de);
VERIFY(d4.count() == static_cast<duration<dbl_emulator>::rep>(de));
}
int
main()
{
test01();
return 0;
}
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
// { dg-require-cstdint "" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 20.8.3.1 duration constructors [time.duration.cons]
#include <chrono>
void
test01()
{
std::chrono::duration<int> d1(1.0);
}
void
test02()
{
using namespace std::chrono;
duration<int, std::micro> d2(8);
duration<int, std::milli> d2_copy(d2);
}
// { dg-error "instantiated from here" "" { target *-*-* } 30 }
// { dg-error "instantiated from here" "" { target *-*-* } 39 }
// { dg-error "not exactly representable" "" { target *-*-* } 202 }
// { dg-error "integral duration with floating point" "" { target *-*-* } 186 }
// { dg-excess-errors "In instantiation of" }
// { dg-options "-std=gnu++0x" }
// { dg-require-cstdint "" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 20.8.3 Class template duration [time.duration]
#include <chrono>
#include <type_traits>
#include <testsuite_hooks.h>
template<typename T>
struct type_emulator
{
type_emulator() : i(T(0)) { }
type_emulator(T j) : i(j) { }
type_emulator(const type_emulator& e) : i(e.i) { }
type_emulator& operator*=(type_emulator a)
{ i *= a.i; return *this; }
type_emulator& operator+=(type_emulator a)
{ i += a.i; return *this; }
operator T () { return i; }
T i;
};
template<typename T>
bool operator==(type_emulator<T> a, type_emulator<T> b)
{ return a.i == b.i; }
template<typename T>
bool operator<(type_emulator<T> a, type_emulator<T> b)
{ return a.i < b.i; }
template<typename T>
type_emulator<T> operator+(type_emulator<T> a, type_emulator<T> b)
{ return a += b; }
template<typename T>
type_emulator<T> operator*(type_emulator<T> a, type_emulator<T> b)
{ return a *= b; }
namespace std
{
template<typename T, typename U>
struct common_type<type_emulator<T>, U>
{ typedef typename common_type<T,U>::type type; };
template<typename T, typename U>
struct common_type<U, type_emulator<T>>
{ typedef typename common_type<U,T>::type type; };
template<typename T, typename U>
struct common_type<type_emulator<T>, type_emulator<U>>
{ typedef typename common_type<T,U>::type type; };
namespace chrono
{
template<typename T>
struct treat_as_floating_point<type_emulator<T>>
: is_floating_point<T>
{ };
}
}
typedef type_emulator<int> int_emulator;
typedef type_emulator<double> dbl_emulator;
// 20.8.3.1 duration constructors [time.duration.cons]
void
test01()
{
bool test __attribute__((unused)) = true;
using namespace std::chrono;
duration<int> d0(3);
duration<int> d0_copy(d0);
VERIFY(d0_copy.count() == d0.count());
duration<int, std::milli> d1(5);
duration<int, std::micro> d1_copy(d1);
VERIFY(d1.count() * 1000 == d1_copy.count());
duration<double, std::micro> d2(8.0);
duration<double, std::milli> d2_copy(d2);
VERIFY(d2.count() == d2_copy.count() * 1000.0);
duration<int_emulator, std::milli> d3(5);
duration<int_emulator, std::micro> d3_copy(d3);
VERIFY(d3.count() * 1000 == d3_copy.count());
duration<dbl_emulator, std::micro> d4(5.0);
duration<dbl_emulator, std::milli> d4_copy(d4);
VERIFY(d4.count() == d4_copy.count() * dbl_emulator(1000.0));
}
int
main()
{
test01();
return 0;
}
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
// { dg-require-cstdint "" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301, USA.
#include <ratio>
#include <chrono>
template class std::chrono::duration<int>;
template class std::chrono::duration<float, std::ratio<2,3>>;
// { dg-options "-std=gnu++0x" }
// { dg-require-cstdint "" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 20.8.4 Class template time_point [time.point]
#include <chrono>
#include <testsuite_hooks.h>
// 20.8.4.1 time_point constructors [time.point.cons]
void
test01()
{
bool test __attribute__((unused)) = true;
using namespace std::chrono;
time_point<system_clock> t1;
VERIFY(t1.time_since_epoch() == system_clock::duration::zero());
time_point<monotonic_clock> t2;
VERIFY(t2.time_since_epoch() == monotonic_clock::duration::zero());
time_point<high_resolution_clock> t3;
VERIFY(t3.time_since_epoch() == high_resolution_clock::duration::zero());
}
int
main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// { dg-require-cstdint "" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 20.8.4 Class template time_point [time.point]
#include <chrono>
#include <testsuite_hooks.h>
// 20.8.4.3 time_point arithmetic [time.point.arithmetic]
void
test01()
{
bool test __attribute__((unused)) = true;
using namespace std::chrono;
time_point<system_clock> t1, t2;
t1 += seconds(1);
VERIFY(t2.time_since_epoch() + seconds(1) == t1.time_since_epoch());
t1 -= std::chrono::seconds(1);
VERIFY(t2.time_since_epoch() == t1.time_since_epoch());
}
// 20.8.4.5 time_point non-member arithmetic [time.point.nonmember]
void
test02()
{
bool test __attribute__((unused)) = true;
using namespace std::chrono;
time_point<system_clock> t1;
time_point<system_clock> t2(t1 + seconds(1));
VERIFY(t2.time_since_epoch() == t1.time_since_epoch() + seconds(1));
time_point<system_clock> t3(seconds(1) + t1);
VERIFY(t3.time_since_epoch() == t1.time_since_epoch() + seconds(1));
time_point<system_clock> t4(seconds(1));
time_point<system_clock> t5(seconds(2));
time_point<system_clock> t6(t5 - seconds(1));
VERIFY(t6.time_since_epoch() == t4.time_since_epoch());
time_point<system_clock> t7(t5 - t4);
VERIFY(t7.time_since_epoch() == t4.time_since_epoch());
}
int
main()
{
test01();
test02();
return 0;
}
// { dg-options "-std=gnu++0x" }
// { dg-require-cstdint "" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 20.8.4 Class template time_point [time.point]
#include <chrono>
#include <testsuite_hooks.h>
// 20.8.4.6 time_point comparisons [time.point.comparisons]
void
test01()
{
bool test __attribute__((unused)) = true;
using namespace std::chrono;
time_point<system_clock> t1(seconds(1));
time_point<system_clock> t2(seconds(1));
time_point<system_clock> t3(seconds(2));
VERIFY(t1 == t2);
VERIFY(t1 != t3);
VERIFY(t1 < t3);
VERIFY(t1 <= t3);
VERIFY(t1 <= t2);
VERIFY(t3 > t1);
VERIFY(t3 >= t1);
VERIFY(t2 >= t1);
}
int
main()
{
test01();
return 0;
}
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
// { dg-require-cstdint "" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301, USA.
#include <chrono>
template class std::chrono::time_point<std::chrono::system_clock>;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment