Implement P0007: Constant View: A proposal for a std::as_const helper function template.

llvm-svn: 253274
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: dbd2d32892e83d270b6fedc54ea301f75e8ae0ac
diff --git a/include/utility b/include/utility
index 8b982da..2975320 100644
--- a/include/utility
+++ b/include/utility
@@ -52,6 +52,9 @@
     >::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 @@
     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/test/std/utilities/utility/as_const/as_const.fail.cpp b/test/std/utilities/utility/as_const/as_const.fail.cpp
new file mode 100644
index 0000000..6334e14
--- /dev/null
+++ b/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/test/std/utilities/utility/as_const/as_const.pass.cpp b/test/std/utilities/utility/as_const/as_const.pass.cpp
new file mode 100644
index 0000000..ff3f84a
--- /dev/null
+++ b/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/www/cxx1z_status.html b/www/cxx1z_status.html
index 67a334f..462c0bd 100644
--- a/www/cxx1z_status.html
+++ b/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>