[PATCH] D46975: Implement deduction guides for `std::deque`
Marshall Clow via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed May 16 13:55:33 PDT 2018
mclow.lists created this revision.
mclow.lists added a reviewer: EricWF.
Based off of http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0433r2.html
https://reviews.llvm.org/D46975
Files:
include/deque
test/std/containers/sequences/deque/deque.cons/deduct.pass.cpp
Index: test/std/containers/sequences/deque/deque.cons/deduct.pass.cpp
===================================================================
--- test/std/containers/sequences/deque/deque.cons/deduct.pass.cpp
+++ test/std/containers/sequences/deque/deque.cons/deduct.pass.cpp
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <array>
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+// XFAIL: libcpp-no-deduction-guides
+
+
+// template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
+// deque(InputIterator, InputIterator, Allocator = Allocator())
+// -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>;
+//
+
+
+#include <deque>
+#include <iterator>
+#include <cassert>
+#include <cstddef>
+#include <climits> // INT_MAX
+
+#include "test_macros.h"
+#include "test_iterators.h"
+
+
+int main()
+{
+
+ {
+ const int arr[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ std::deque deq(std::begin(arr), std::end(arr));
+
+ static_assert(std::is_same_v<decltype(deq), std::deque<int>>, "");
+ assert(std::equal(deq.begin(), deq.end(), std::begin(arr), std::end(arr)));
+ }
+
+ {
+ const long arr[] = {INT_MAX, 1L + INT_MAX, 2L, 3L };
+ std::deque deq(std::begin(arr), std::end(arr), std::allocator<long>());
+ static_assert(std::is_same_v<decltype(deq)::value_type, long>, "");
+ assert(deq.size() == 4);
+ assert(deq[0] == INT_MAX);
+ assert(deq[1] == 1L + INT_MAX);
+ assert(deq[2] == 2L);
+ }
+}
Index: include/deque
===================================================================
--- include/deque
+++ include/deque
@@ -128,6 +128,10 @@
void clear() noexcept;
};
+template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
+ deque(InputIterator, InputIterator, Allocator = Allocator())
+ -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>;
+
template <class T, class Allocator>
bool operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
template <class T, class Allocator>
@@ -1461,6 +1465,23 @@
void __move_assign(deque& __c, false_type);
};
+#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+template<class _InputIterator,
+ class _Alloc = typename std::allocator<typename iterator_traits<_InputIterator>::value_type>,
+ class = typename enable_if<__is_allocator<_Alloc>::value, void>::type
+ >
+deque(_InputIterator, _InputIterator)
+ -> deque<typename iterator_traits<_InputIterator>::value_type, _Alloc>;
+
+template<class _InputIterator,
+ class _Alloc,
+ class = typename enable_if<__is_allocator<_Alloc>::value, void>::type
+ >
+deque(_InputIterator, _InputIterator, _Alloc)
+ -> deque<typename iterator_traits<_InputIterator>::value_type, _Alloc>;
+#endif
+
+
template <class _Tp, class _Allocator>
deque<_Tp, _Allocator>::deque(size_type __n)
{
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46975.147172.patch
Type: text/x-patch
Size: 3272 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180516/49a23790/attachment.bin>
More information about the cfe-commits
mailing list