summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2018-01-11 19:36:22 +0000
committerMarshall Clow <mclow.lists@gmail.com>2018-01-11 19:36:22 +0000
commit0e22bf8cb963d34439c8aef38acf626c29f0f804 (patch)
treef00550065a28bacd646c0a27bf4e90de8bc1ae7e
parentaac638eb1e96629badbdd68a0e68e96c61bf9d21 (diff)
downloadbcm5719-llvm-0e22bf8cb963d34439c8aef38acf626c29f0f804.tar.gz
bcm5719-llvm-0e22bf8cb963d34439c8aef38acf626c29f0f804.zip
Implement an _is_allocator type trait for use in deduction guides.
llvm-svn: 322306
-rw-r--r--libcxx/include/memory10
-rw-r--r--libcxx/test/libcxx/memory/is_allocator.pass.cpp41
2 files changed, 51 insertions, 0 deletions
diff --git a/libcxx/include/memory b/libcxx/include/memory
index d6b427b941b..56502e2a15a 100644
--- a/libcxx/include/memory
+++ b/libcxx/include/memory
@@ -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
diff --git a/libcxx/test/libcxx/memory/is_allocator.pass.cpp b/libcxx/test/libcxx/memory/is_allocator.pass.cpp
new file mode 100644
index 00000000000..c33b7e8295b
--- /dev/null
+++ b/libcxx/test/libcxx/memory/is_allocator.pass.cpp
@@ -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>();
+}
OpenPOWER on IntegriCloud