[libcxx] r322306 - Implement an _is_allocator type trait for use in deduction guides.

Marshall Clow via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 11 11:36:23 PST 2018


Author: marshall
Date: Thu Jan 11 11:36:22 2018
New Revision: 322306

URL: http://llvm.org/viewvc/llvm-project?rev=322306&view=rev
Log:
Implement an _is_allocator type trait for use in deduction guides.

Added:
    libcxx/trunk/test/libcxx/memory/
    libcxx/trunk/test/libcxx/memory/is_allocator.pass.cpp
Modified:
    libcxx/trunk/include/memory

Modified: libcxx/trunk/include/memory
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=322306&r1=322305&r2=322306&view=diff
==============================================================================
--- libcxx/trunk/include/memory (original)
+++ libcxx/trunk/include/memory Thu Jan 11 11:36:22 2018
@@ -5597,6 +5597,16 @@ struct __temp_value {
     };
 #endif
 
+#if _LIBCPP_STD_VER > 14
+template<typename _Alloc, typename = void>
+struct __is_allocator : false_type {};
+
+template<typename _Alloc>
+struct __is_allocator<_Alloc,
+     void_t<typename _Alloc::value_type, decltype(_VSTD::declval<_Alloc&>().allocate(size_t{}))>>
+   : true_type {};
+#endif
+
 _LIBCPP_END_NAMESPACE_STD
 
 _LIBCPP_POP_MACROS

Added: libcxx/trunk/test/libcxx/memory/is_allocator.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/memory/is_allocator.pass.cpp?rev=322306&view=auto
==============================================================================
--- libcxx/trunk/test/libcxx/memory/is_allocator.pass.cpp (added)
+++ libcxx/trunk/test/libcxx/memory/is_allocator.pass.cpp Thu Jan 11 11:36:22 2018
@@ -0,0 +1,41 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+//
+
+// <memory>
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+// template<typename _Alloc>
+// struct __is_allocator;
+
+// Is either true_type or false_type depending on if A is an allocator.
+
+#include <memory>
+#include <string>
+
+#include "test_macros.h"
+#include "min_allocator.h"
+#include "test_allocator.h"
+
+template <typename T>
+void test_allocators()
+{
+	static_assert( std::__is_allocator<std::allocator<T>>::value, "" );
+	static_assert( std::__is_allocator<test_allocator<T>>::value, "" );
+	static_assert( std::__is_allocator<min_allocator<T>>::value, "" );
+}
+
+
+int main()
+{
+//	test_allocators<void>();
+	test_allocators<char>();
+	test_allocators<int>();
+	test_allocators<std::string>();
+}




More information about the cfe-commits mailing list