[libcxx] r229509 - [libcxx] Add <experimental/ratio>
Eric Fiselier
eric at efcs.ca
Tue Feb 17 08:52:03 PST 2015
Author: ericwf
Date: Tue Feb 17 10:52:03 2015
New Revision: 229509
URL: http://llvm.org/viewvc/llvm-project?rev=229509&view=rev
Log:
[libcxx] Add <experimental/ratio>
Summary:
This patch is pretty simple. It just adds the _v traits from <ratio>.
The draft can be found here.
Reviewers: jroelofs, K-ballo, mclow.lists
Reviewed By: mclow.lists
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D7351
Added:
libcxx/trunk/include/experimental/ratio
libcxx/trunk/test/libcxx/experimental/utilities/ratio/
libcxx/trunk/test/libcxx/experimental/utilities/ratio/header.ratio.synop/
libcxx/trunk/test/libcxx/experimental/utilities/ratio/header.ratio.synop/includes.pass.cpp
libcxx/trunk/test/libcxx/experimental/utilities/ratio/version.pass.cpp
libcxx/trunk/test/std/experimental/utilities/ratio/
libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/
libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/includes.pass.cpp
libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_equal_v.pass.cpp
libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_greater_equal_v.pass.cpp
libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_greater_v.pass.cpp
libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_less_equal_v.pass.cpp
libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_less_v.pass.cpp
libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_not_equal_v.pass.cpp
libcxx/trunk/test/std/experimental/utilities/ratio/nothing_to_do.pass.cpp
Added: libcxx/trunk/include/experimental/ratio
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/ratio?rev=229509&view=auto
==============================================================================
--- libcxx/trunk/include/experimental/ratio (added)
+++ libcxx/trunk/include/experimental/ratio Tue Feb 17 10:52:03 2015
@@ -0,0 +1,77 @@
+// -*- C++ -*-
+//===------------------------------ ratio ---------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_EXPERIMENTAL_RATIO
+#define _LIBCPP_EXPERIMENTAL_RATIO
+
+/**
+ experimental/ratio synopsis
+ C++1y
+#include <ratio>
+
+namespace std {
+namespace experimental {
+inline namespace fundamentals_v1 {
+
+ // See C++14 20.11.5, ratio comparison
+ template <class R1, class R2> constexpr bool ratio_equal_v
+ = ratio_equal<R1, R2>::value;
+ template <class R1, class R2> constexpr bool ratio_not_equal_v
+ = ratio_not_equal<R1, R2>::value;
+ template <class R1, class R2> constexpr bool ratio_less_v
+ = ratio_less<R1, R2>::value;
+ template <class R1, class R2> constexpr bool ratio_less_equal_v
+ = ratio_less_equal<R1, R2>::value;
+ template <class R1, class R2> constexpr bool ratio_greater_v
+ = ratio_greater<R1, R2>::value;
+ template <class R1, class R2> constexpr bool ratio_greater_equal_v
+ = ratio_greater_equal<R1, R2>::value;
+
+} // namespace fundamentals_v1
+} // namespace experimental
+} // namespace std
+
+*/
+
+#include <experimental/__config>
+
+#if _LIBCPP_STD_VER > 11
+
+#include <ratio>
+
+_LIBCPP_BEGIN_NAMESPACE_LFTS
+
+#if __has_feature(cxx_variable_templates)
+
+template <class _R1, class _R2> _LIBCPP_CONSTEXPR bool ratio_equal_v
+ = ratio_equal<_R1, _R2>::value;
+
+template <class _R1, class _R2> _LIBCPP_CONSTEXPR bool ratio_not_equal_v
+ = ratio_not_equal<_R1, _R2>::value;
+
+template <class _R1, class _R2> _LIBCPP_CONSTEXPR bool ratio_less_v
+ = ratio_less<_R1, _R2>::value;
+
+template <class _R1, class _R2> _LIBCPP_CONSTEXPR bool ratio_less_equal_v
+ = ratio_less_equal<_R1, _R2>::value;
+
+template <class _R1, class _R2> _LIBCPP_CONSTEXPR bool ratio_greater_v
+ = ratio_greater<_R1, _R2>::value;
+
+template <class _R1, class _R2> _LIBCPP_CONSTEXPR bool ratio_greater_equal_v
+ = ratio_greater_equal<_R1, _R2>::value;
+
+#endif /* __has_feature(cxx_variable_templates) */
+
+_LIBCPP_END_NAMESPACE_LFTS
+
+#endif /* _LIBCPP_STD_VER > 11 */
+
+#endif _LIBCPP_EXPERIMENTAL_RATIO
\ No newline at end of file
Added: libcxx/trunk/test/libcxx/experimental/utilities/ratio/header.ratio.synop/includes.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/experimental/utilities/ratio/header.ratio.synop/includes.pass.cpp?rev=229509&view=auto
==============================================================================
--- libcxx/trunk/test/libcxx/experimental/utilities/ratio/header.ratio.synop/includes.pass.cpp (added)
+++ libcxx/trunk/test/libcxx/experimental/utilities/ratio/header.ratio.synop/includes.pass.cpp Tue Feb 17 10:52:03 2015
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <experimental/ratio>
+
+// Test that <ratio> is included.
+
+#include <experimental/ratio>
+
+#ifndef _LIBCPP_STD_VER > 11
+# ifndef _LIBCPP_RATIO
+# error " <experimental/ratio> must include <ratio>"
+# endif
+#endif
+
+int main()
+{
+}
Added: libcxx/trunk/test/libcxx/experimental/utilities/ratio/version.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/experimental/utilities/ratio/version.pass.cpp?rev=229509&view=auto
==============================================================================
--- libcxx/trunk/test/libcxx/experimental/utilities/ratio/version.pass.cpp (added)
+++ libcxx/trunk/test/libcxx/experimental/utilities/ratio/version.pass.cpp Tue Feb 17 10:52:03 2015
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <experimental/ratio>
+
+#include <experimental/ratio>
+
+#ifndef _LIBCPP_VERSION
+#error _LIBCPP_VERSION not defined
+#endif
+
+int main()
+{
+}
Added: libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/includes.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/includes.pass.cpp?rev=229509&view=auto
==============================================================================
--- libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/includes.pass.cpp (added)
+++ libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/includes.pass.cpp Tue Feb 17 10:52:03 2015
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11
+
+// <experimental/ratio>
+
+// Test that <ratio> is included.
+
+#include <experimental/ratio>
+
+int main()
+{
+ std::ratio<100> x;
+}
Added: libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_equal_v.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_equal_v.pass.cpp?rev=229509&view=auto
==============================================================================
--- libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_equal_v.pass.cpp (added)
+++ libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_equal_v.pass.cpp Tue Feb 17 10:52:03 2015
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11
+
+// <experimental/ratio>
+
+// template <class R1, class R2> constexpr bool ratio_equal_v;
+
+#include <experimental/ratio>
+#include <type_traits>
+
+namespace ex = std::experimental;
+
+int main()
+{
+ {
+ typedef std::ratio<1, 1> R1;
+ typedef std::ratio<1, 1> R2;
+ static_assert(
+ ex::ratio_equal_v<R1, R2>, ""
+ );
+ static_assert(
+ ex::ratio_equal_v<R1, R2> == std::ratio_equal<R1, R2>::value, ""
+ );
+ static_assert(
+ std::is_same<decltype(ex::ratio_equal_v<R1, R2>), const bool>::value
+ , ""
+ );
+ }
+ {
+ typedef std::ratio<1, 1> R1;
+ typedef std::ratio<1, -1> R2;
+ static_assert(
+ !ex::ratio_equal_v<R1, R2>, ""
+ );
+ static_assert(
+ ex::ratio_equal_v<R1, R2> == std::ratio_equal<R1, R2>::value, ""
+ );
+ }
+}
Added: libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_greater_equal_v.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_greater_equal_v.pass.cpp?rev=229509&view=auto
==============================================================================
--- libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_greater_equal_v.pass.cpp (added)
+++ libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_greater_equal_v.pass.cpp Tue Feb 17 10:52:03 2015
@@ -0,0 +1,61 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11
+
+// <experimental/ratio>
+
+// template <class R1, class R2> constexpr bool ratio_greater_equal_v;
+
+#include <experimental/ratio>
+#include <type_traits>
+
+namespace ex = std::experimental;
+
+int main()
+{
+ {
+ typedef std::ratio<1, 2> R1;
+ typedef std::ratio<1, 1> R2;
+ static_assert(
+ !ex::ratio_greater_equal_v<R1, R2>, ""
+ );
+ static_assert(
+ ex::ratio_greater_equal_v<R1, R2>
+ == std::ratio_greater_equal<R1, R2>::value, ""
+ );
+ static_assert(
+ std::is_same<
+ decltype(ex::ratio_greater_equal_v<R1, R2>), const bool>::value
+ , ""
+ );
+ }
+ {
+ typedef std::ratio<1, 1> R1;
+ typedef std::ratio<1, 1> R2;
+ static_assert(
+ ex::ratio_greater_equal_v<R1, R2>, ""
+ );
+ static_assert(
+ ex::ratio_greater_equal_v<R1, R2>
+ == std::ratio_greater_equal<R1, R2>::value, ""
+ );
+ }
+ {
+ typedef std::ratio<2, 1> R1;
+ typedef std::ratio<1, 1> R2;
+ static_assert(
+ ex::ratio_greater_equal_v<R1, R2>, ""
+ );
+ static_assert(
+ ex::ratio_greater_equal_v<R1, R2>
+ == std::ratio_greater_equal<R1, R2>::value, ""
+ );
+ }
+}
Added: libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_greater_v.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_greater_v.pass.cpp?rev=229509&view=auto
==============================================================================
--- libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_greater_v.pass.cpp (added)
+++ libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_greater_v.pass.cpp Tue Feb 17 10:52:03 2015
@@ -0,0 +1,57 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11
+
+// <experimental/ratio>
+
+// template <class R1, class R2> constexpr bool ratio_greater_v;
+
+#include <experimental/ratio>
+#include <type_traits>
+
+namespace ex = std::experimental;
+
+int main()
+{
+ {
+ typedef std::ratio<1, 2> R1;
+ typedef std::ratio<1, 1> R2;
+ static_assert(
+ !ex::ratio_greater_v<R1, R2>, ""
+ );
+ static_assert(
+ ex::ratio_greater_v<R1, R2> == std::ratio_greater<R1, R2>::value, ""
+ );
+ static_assert(
+ std::is_same<decltype(ex::ratio_greater_v<R1, R2>), const bool>::value
+ , ""
+ );
+ }
+ {
+ typedef std::ratio<1, 1> R1;
+ typedef std::ratio<1, 1> R2;
+ static_assert(
+ !ex::ratio_greater_v<R1, R2>, ""
+ );
+ static_assert(
+ ex::ratio_greater_v<R1, R2> == std::ratio_greater<R1, R2>::value, ""
+ );
+ }
+ {
+ typedef std::ratio<2, 1> R1;
+ typedef std::ratio<1, 1> R2;
+ static_assert(
+ ex::ratio_greater_v<R1, R2>, ""
+ );
+ static_assert(
+ ex::ratio_greater_v<R1, R2> == std::ratio_greater<R1, R2>::value, ""
+ );
+ }
+}
Added: libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_less_equal_v.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_less_equal_v.pass.cpp?rev=229509&view=auto
==============================================================================
--- libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_less_equal_v.pass.cpp (added)
+++ libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_less_equal_v.pass.cpp Tue Feb 17 10:52:03 2015
@@ -0,0 +1,57 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11
+
+// <experimental/ratio>
+
+// template <class R1, class R2> constexpr bool ratio_less_equal_v;
+
+#include <experimental/ratio>
+#include <type_traits>
+
+namespace ex = std::experimental;
+
+int main()
+{
+ {
+ typedef std::ratio<1, 2> R1;
+ typedef std::ratio<1, 1> R2;
+ static_assert(
+ ex::ratio_less_equal_v<R1, R2>, ""
+ );
+ static_assert(
+ ex::ratio_less_equal_v<R1, R2> == std::ratio_less_equal<R1, R2>::value, ""
+ );
+ static_assert(
+ std::is_same<decltype(ex::ratio_less_equal_v<R1, R2>), const bool>::value
+ , ""
+ );
+ }
+ {
+ typedef std::ratio<1, 1> R1;
+ typedef std::ratio<1, 1> R2;
+ static_assert(
+ ex::ratio_less_equal_v<R1, R2>, ""
+ );
+ static_assert(
+ ex::ratio_less_equal_v<R1, R2> == std::ratio_less_equal<R1, R2>::value, ""
+ );
+ }
+ {
+ typedef std::ratio<2, 1> R1;
+ typedef std::ratio<1, 1> R2;
+ static_assert(
+ !ex::ratio_less_equal_v<R1, R2>, ""
+ );
+ static_assert(
+ ex::ratio_less_equal_v<R1, R2> == std::ratio_less_equal<R1, R2>::value, ""
+ );
+ }
+}
Added: libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_less_v.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_less_v.pass.cpp?rev=229509&view=auto
==============================================================================
--- libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_less_v.pass.cpp (added)
+++ libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_less_v.pass.cpp Tue Feb 17 10:52:03 2015
@@ -0,0 +1,57 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11
+
+// <experimental/ratio>
+
+// template <class R1, class R2> constexpr bool ratio_less_v;
+
+#include <experimental/ratio>
+#include <type_traits>
+
+namespace ex = std::experimental;
+
+int main()
+{
+ {
+ typedef std::ratio<1, 2> R1;
+ typedef std::ratio<1, 1> R2;
+ static_assert(
+ ex::ratio_less_v<R1, R2>, ""
+ );
+ static_assert(
+ ex::ratio_less_v<R1, R2> == std::ratio_less<R1, R2>::value, ""
+ );
+ static_assert(
+ std::is_same<decltype(ex::ratio_less_v<R1, R2>), const bool>::value
+ , ""
+ );
+ }
+ {
+ typedef std::ratio<1, 1> R1;
+ typedef std::ratio<1, 1> R2;
+ static_assert(
+ !ex::ratio_less_v<R1, R2>, ""
+ );
+ static_assert(
+ ex::ratio_less_v<R1, R2> == std::ratio_less<R1, R2>::value, ""
+ );
+ }
+ {
+ typedef std::ratio<2, 1> R1;
+ typedef std::ratio<1, 1> R2;
+ static_assert(
+ !ex::ratio_less_v<R1, R2>, ""
+ );
+ static_assert(
+ ex::ratio_less_v<R1, R2> == std::ratio_less<R1, R2>::value, ""
+ );
+ }
+}
Added: libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_not_equal_v.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_not_equal_v.pass.cpp?rev=229509&view=auto
==============================================================================
--- libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_not_equal_v.pass.cpp (added)
+++ libcxx/trunk/test/std/experimental/utilities/ratio/header.ratio.synop/ratio_not_equal_v.pass.cpp Tue Feb 17 10:52:03 2015
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11
+
+// <experimental/ratio>
+
+// template <class R1, class R2> constexpr bool ratio_not_equal_v;
+
+#include <experimental/ratio>
+#include <type_traits>
+
+namespace ex = std::experimental;
+
+int main()
+{
+ {
+ typedef std::ratio<1, 1> R1;
+ typedef std::ratio<1, -1> R2;
+ static_assert(
+ ex::ratio_not_equal_v<R1, R2>, ""
+ );
+ static_assert(
+ ex::ratio_not_equal_v<R1, R2> == std::ratio_not_equal<R1, R2>::value, ""
+ );
+ static_assert(
+ std::is_same<decltype(ex::ratio_not_equal_v<R1, R2>), const bool>::value
+ , ""
+ );
+ }
+ {
+ typedef std::ratio<1, 1> R1;
+ typedef std::ratio<1, 1> R2;
+ static_assert(
+ !ex::ratio_not_equal_v<R1, R2>, ""
+ );
+ static_assert(
+ ex::ratio_not_equal_v<R1, R2> == std::ratio_not_equal<R1, R2>::value, ""
+ );
+ }
+}
Added: libcxx/trunk/test/std/experimental/utilities/ratio/nothing_to_do.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/utilities/ratio/nothing_to_do.pass.cpp?rev=229509&view=auto
==============================================================================
--- libcxx/trunk/test/std/experimental/utilities/ratio/nothing_to_do.pass.cpp (added)
+++ libcxx/trunk/test/std/experimental/utilities/ratio/nothing_to_do.pass.cpp Tue Feb 17 10:52:03 2015
@@ -0,0 +1,13 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
More information about the cfe-commits
mailing list