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();