[libcxx] r305370 - Add an `__is_inplace_index` metafunction.

Michael Park via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 13 22:51:18 PDT 2017


Author: mpark
Date: Wed Jun 14 00:51:18 2017
New Revision: 305370

URL: http://llvm.org/viewvc/llvm-project?rev=305370&view=rev
Log:
Add an `__is_inplace_index` metafunction.

Summary: This is used to constrain `variant`'s converting constructor correctly.

Reviewers: EricWF, mclow.lists

Reviewed By: EricWF, mclow.lists

Differential Revision: https://reviews.llvm.org/D34111

Added:
    libcxx/trunk/test/libcxx/utilities/utility/__is_inplace_index.pass.cpp
    libcxx/trunk/test/libcxx/utilities/utility/__is_inplace_type.pass.cpp
Modified:
    libcxx/trunk/include/utility

Modified: libcxx/trunk/include/utility
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/utility?rev=305370&r1=305369&r2=305370&view=diff
==============================================================================
--- libcxx/trunk/include/utility (original)
+++ libcxx/trunk/include/utility Wed Jun 14 00:51:18 2017
@@ -930,6 +930,12 @@ template <class _Tp> struct __is_inplace
 template <class _Tp>
 using __is_inplace_type = __is_inplace_type_imp<__uncvref_t<_Tp>>;
 
+template <class _Tp> struct __is_inplace_index_imp : false_type {};
+template <size_t _Idx> struct __is_inplace_index_imp<in_place_index_t<_Idx>> : true_type {};
+
+template <class _Tp>
+using __is_inplace_index = __is_inplace_index_imp<__uncvref_t<_Tp>>;
+
 #endif // _LIBCPP_STD_VER > 14
 
 template <class _Arg, class _Result>

Added: libcxx/trunk/test/libcxx/utilities/utility/__is_inplace_index.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/utilities/utility/__is_inplace_index.pass.cpp?rev=305370&view=auto
==============================================================================
--- libcxx/trunk/test/libcxx/utilities/utility/__is_inplace_index.pass.cpp (added)
+++ libcxx/trunk/test/libcxx/utilities/utility/__is_inplace_index.pass.cpp Wed Jun 14 00:51:18 2017
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// template <class _Tp> using __is_inplace_index
+
+#include <utility>
+
+struct S {};
+
+int main() {
+  using I = std::in_place_index_t<0>;
+  static_assert( std::__is_inplace_index<I>::value, "");
+  static_assert( std::__is_inplace_index<const I>::value, "");
+  static_assert( std::__is_inplace_index<const volatile I>::value, "");
+  static_assert( std::__is_inplace_index<I&>::value, "");
+  static_assert( std::__is_inplace_index<const I&>::value, "");
+  static_assert( std::__is_inplace_index<const volatile I&>::value, "");
+  static_assert( std::__is_inplace_index<I&&>::value, "");
+  static_assert( std::__is_inplace_index<const I&&>::value, "");
+  static_assert( std::__is_inplace_index<const volatile I&&>::value, "");
+  static_assert(!std::__is_inplace_index<std::in_place_type_t<int>>::value, "");
+  static_assert(!std::__is_inplace_index<std::in_place_t>::value, "");
+  static_assert(!std::__is_inplace_index<void>::value, "");
+  static_assert(!std::__is_inplace_index<int>::value, "");
+  static_assert(!std::__is_inplace_index<S>::value, "");
+}

Added: libcxx/trunk/test/libcxx/utilities/utility/__is_inplace_type.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/utilities/utility/__is_inplace_type.pass.cpp?rev=305370&view=auto
==============================================================================
--- libcxx/trunk/test/libcxx/utilities/utility/__is_inplace_type.pass.cpp (added)
+++ libcxx/trunk/test/libcxx/utilities/utility/__is_inplace_type.pass.cpp Wed Jun 14 00:51:18 2017
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// template <class _Tp> using __is_inplace_type
+
+#include <utility>
+
+struct S {};
+
+int main() {
+  using T = std::in_place_type_t<int>;
+  static_assert( std::__is_inplace_type<T>::value, "");
+  static_assert( std::__is_inplace_type<const T>::value, "");
+  static_assert( std::__is_inplace_type<const volatile T>::value, "");
+  static_assert( std::__is_inplace_type<T&>::value, "");
+  static_assert( std::__is_inplace_type<const T&>::value, "");
+  static_assert( std::__is_inplace_type<const volatile T&>::value, "");
+  static_assert( std::__is_inplace_type<T&&>::value, "");
+  static_assert( std::__is_inplace_type<const T&&>::value, "");
+  static_assert( std::__is_inplace_type<const volatile T&&>::value, "");
+  static_assert(!std::__is_inplace_type<std::in_place_index_t<0>>::value, "");
+  static_assert(!std::__is_inplace_type<std::in_place_t>::value, "");
+  static_assert(!std::__is_inplace_type<void>::value, "");
+  static_assert(!std::__is_inplace_type<int>::value, "");
+  static_assert(!std::__is_inplace_type<S>::value, "");
+}




More information about the cfe-commits mailing list