summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2015-11-17 00:08:08 +0000
committerMarshall Clow <mclow.lists@gmail.com>2015-11-17 00:08:08 +0000
commitdbd2d32892e83d270b6fedc54ea301f75e8ae0ac (patch)
treed4dc377efe8e0c91f575fa08244ac7dbfeeded0f
parentba1057022cd442258d722235f17c5c97a591c158 (diff)
downloadbcm5719-llvm-dbd2d32892e83d270b6fedc54ea301f75e8ae0ac.tar.gz
bcm5719-llvm-dbd2d32892e83d270b6fedc54ea301f75e8ae0ac.zip
Implement P0007: Constant View: A proposal for a std::as_const helper function template.
llvm-svn: 253274
-rw-r--r--libcxx/include/utility8
-rw-r--r--libcxx/test/std/utilities/utility/as_const/as_const.fail.cpp22
-rw-r--r--libcxx/test/std/utilities/utility/as_const/as_const.pass.cpp46
-rw-r--r--libcxx/www/cxx1z_status.html2
4 files changed, 77 insertions, 1 deletions
diff --git a/libcxx/include/utility b/libcxx/include/utility
index 8b982da72b9..29753206ae7 100644
--- a/libcxx/include/utility
+++ b/libcxx/include/utility
@@ -52,6 +52,9 @@ template <class T>
>::type
move_if_noexcept(T& x) noexcept; // constexpr in C++14
+template <class T> constexpr add_const<T>_t& as_const(T& t) noexcept; // C++17
+template <class T> void as_const(const T&&) = delete; // C++17
+
template <class T> typename add_rvalue_reference<T>::type declval() noexcept;
template <class T1, class T2>
@@ -242,6 +245,11 @@ move_if_noexcept(_Tp& __x) _NOEXCEPT
return _VSTD::move(__x);
}
+#if _LIBCPP_STD_VER > 14
+template <class _Tp> constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { return __t; }
+template <class _Tp> void as_const(const _Tp&&) = delete;
+#endif
+
struct _LIBCPP_TYPE_VIS_ONLY piecewise_construct_t { };
#if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_UTILITY)
extern const piecewise_construct_t piecewise_construct;// = piecewise_construct_t();
diff --git a/libcxx/test/std/utilities/utility/as_const/as_const.fail.cpp b/libcxx/test/std/utilities/utility/as_const/as_const.fail.cpp
new file mode 100644
index 00000000000..6334e146025
--- /dev/null
+++ b/libcxx/test/std/utilities/utility/as_const/as_const.fail.cpp
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, c++14
+
+// template <class T> constexpr add_const<T>& as_const(T& t) noexcept; // C++17
+// template <class T> add_const<T>& as_const(const T&&) = delete; // C++17
+
+#include <utility>
+
+struct S {int i;};
+
+int main()
+{
+ std::as_const(S{});
+}
diff --git a/libcxx/test/std/utilities/utility/as_const/as_const.pass.cpp b/libcxx/test/std/utilities/utility/as_const/as_const.pass.cpp
new file mode 100644
index 00000000000..ff3f84a5532
--- /dev/null
+++ b/libcxx/test/std/utilities/utility/as_const/as_const.pass.cpp
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, c++14
+
+// template <class T> constexpr add_const<T>& as_const(T& t) noexcept; // C++17
+// template <class T> add_const<T>& as_const(const T&&) = delete; // C++17
+
+#include <utility>
+#include <cassert>
+
+struct S {int i;};
+bool operator==(const S& x, const S& y) { return x.i == y.i; }
+bool operator==(const volatile S& x, const volatile S& y) { return x.i == y.i; }
+
+template<typename T>
+void test(T& t)
+{
+ static_assert(std::is_const<typename std::remove_reference<decltype(std::as_const (t))>::type>::value, "");
+ static_assert(std::is_const<typename std::remove_reference<decltype(std::as_const< T>(t))>::type>::value, "");
+ static_assert(std::is_const<typename std::remove_reference<decltype(std::as_const<const T>(t))>::type>::value, "");
+ static_assert(std::is_const<typename std::remove_reference<decltype(std::as_const<volatile T>(t))>::type>::value, "");
+ static_assert(std::is_const<typename std::remove_reference<decltype(std::as_const<const volatile T>(t))>::type>::value, "");
+
+ assert(std::as_const(t) == t);
+ assert(std::as_const< T>(t) == t);
+ assert(std::as_const<const T>(t) == t);
+ assert(std::as_const<volatile T>(t) == t);
+ assert(std::as_const<const volatile T>(t) == t);
+}
+
+int main()
+{
+ int i = 3;
+ double d = 4.0;
+ S s{2};
+ test(i);
+ test(d);
+ test(s);
+}
diff --git a/libcxx/www/cxx1z_status.html b/libcxx/www/cxx1z_status.html
index 67a334f52cc..462c0bd14e4 100644
--- a/libcxx/www/cxx1z_status.html
+++ b/libcxx/www/cxx1z_status.html
@@ -73,7 +73,7 @@
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0004R1.html">P0004R1</a></td><td>LWG</td><td>Remove Deprecated iostreams aliases.</td><td>Kona</td><td>Complete</td><td>3.8</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0006R0.html">P0006R0</a></td><td>LWG</td><td>Adopt Type Traits Variable Templates for C++17.</td><td>Kona</td><td>In progress</td><td></td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0092R1.html">P0092R1</a></td><td>LWG</td><td>Polishing &lt;chrono&gt;</td><td>Kona</td><td>Complete</td><td>3.8</td></tr>
- <tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0007R1.html">P0007R1</a></td><td>LWG</td><td>Constant View: A proposal for a <tt>std::as_const</tt> helper function template.</td><td>Kona</td><td>In progress</td><td></td></tr>
+ <tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0007R1.html">P0007R1</a></td><td>LWG</td><td>Constant View: A proposal for a <tt>std::as_const</tt> helper function template.</td><td>Kona</td><td>Complete</td><td>3.8</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0156R0.htm" >P0156R0</a></td><td>LWG</td><td>Variadic lock_guard(rev 3).</td><td>Kona</td><td></td><td></td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0074R0.html">P0074R0</a></td><td>LWG</td><td>Making <tt>std::owner_less</tt> more flexible</td><td>Kona</td><td>Complete</td><td>3.8</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0013R1.html">P0013R1</a></td><td>LWG</td><td>Logical type traits rev 2</td><td>Kona</td><td>Complete</td><td>3.8</td></tr>
OpenPOWER on IntegriCloud