Add deduction guides for sequence containers (P0433R2, partial)
authorJonathan Wakely <jwakely@redhat.com>
Fri, 9 Jun 2017 11:04:53 +0000 (12:04 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 9 Jun 2017 11:04:53 +0000 (12:04 +0100)
* include/bits/forward_list.h (forward_list): Add deduction guide.
* include/bits/stl_deque.h (deque): Likewise.
* include/bits/stl_list.h (list): Likewise.
* include/bits/stl_vector.h (vector): Likewise.
* testsuite/23_containers/deque/cons/deduction.cc: New.
* testsuite/23_containers/forward_list/cons/deduction.cc: New.
* testsuite/23_containers/list/cons/deduction.cc: New.
* testsuite/23_containers/vector/cons/deduction.cc: New.

From-SVN: r249054

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/forward_list.h
libstdc++-v3/include/bits/stl_deque.h
libstdc++-v3/include/bits/stl_list.h
libstdc++-v3/include/bits/stl_vector.h
libstdc++-v3/testsuite/23_containers/deque/cons/deduction.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/forward_list/cons/deduction.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/list/cons/deduction.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/vector/cons/deduction.cc [new file with mode: 0644]

index 6896c15fa6e71b97d1f884c70633af87bcb7605a..6909a1fe84aab32d95a49f46864a37c5ae531913 100644 (file)
@@ -1,3 +1,14 @@
+2017-06-09  Jonathan Wakely  <jwakely@redhat.com>
+
+       * include/bits/forward_list.h (forward_list): Add deduction guide.
+       * include/bits/stl_deque.h (deque): Likewise.
+       * include/bits/stl_list.h (list): Likewise.
+       * include/bits/stl_vector.h (vector): Likewise.
+       * testsuite/23_containers/deque/cons/deduction.cc: New.
+       * testsuite/23_containers/forward_list/cons/deduction.cc: New.
+       * testsuite/23_containers/list/cons/deduction.cc: New.
+       * testsuite/23_containers/vector/cons/deduction.cc: New.
+
 2017-06-08  Jonathan Wakely  <jwakely@redhat.com>
 
        PR libstdc++/81017
index c37bf01345a30739b0d83e43eda9940197657222..f319b7f060700a8d1ab941376fafa8ba19fa5f34 100644 (file)
@@ -1359,6 +1359,16 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       }
     };
 
+#if __cpp_deduction_guides >= 201606
+  template<typename _InputIterator, typename _ValT
+            = typename iterator_traits<_InputIterator>::value_type,
+          typename _Allocator = allocator<_ValT>,
+          typename = _RequireInputIter<_InputIterator>,
+          typename = _RequireAllocator<_Allocator>>
+    forward_list(_InputIterator, _InputIterator, _Allocator = _Allocator())
+      -> forward_list<_ValT, _Allocator>;
+#endif
+
   /**
    *  @brief  Forward list equality comparison.
    *  @param  __lx  A %forward_list
index 6090635b7d615a7146e6727acebaed79c6903c13..e03e7f5808f04f9d3621e3c965d79495c3412667 100644 (file)
@@ -2242,6 +2242,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 #endif
     };
 
+#if __cpp_deduction_guides >= 201606
+  template<typename _InputIterator, typename _ValT
+            = typename iterator_traits<_InputIterator>::value_type,
+          typename _Allocator = allocator<_ValT>,
+          typename = _RequireInputIter<_InputIterator>,
+          typename = _RequireAllocator<_Allocator>>
+    deque(_InputIterator, _InputIterator, _Allocator = _Allocator())
+      -> deque<_ValT, _Allocator>;
+#endif
 
   /**
    *  @brief  Deque equality comparison.
index 0420dbfbba744c4c7de73de967bdcd124d7dac9d..232885af79de82b9b471322fb54a6702b0e1ca1a 100644 (file)
@@ -1867,6 +1867,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
       }
 #endif
     };
+
+#if __cpp_deduction_guides >= 201606
+  template<typename _InputIterator, typename _ValT
+            = typename iterator_traits<_InputIterator>::value_type,
+          typename _Allocator = allocator<_ValT>,
+          typename = _RequireInputIter<_InputIterator>,
+          typename = _RequireAllocator<_Allocator>>
+    list(_InputIterator, _InputIterator, _Allocator = _Allocator())
+      -> list<_ValT, _Allocator>;
+#endif
+
 _GLIBCXX_END_NAMESPACE_CXX11
 
   /**
index fb882126cf984f69b8b927a4a4bf0ff0dcc798fa..7ee3ce9689004124dbd3c1a584043a000bbb892d 100644 (file)
@@ -1580,6 +1580,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 #endif
     };
 
+#if __cpp_deduction_guides >= 201606
+  template<typename _InputIterator, typename _ValT
+            = typename iterator_traits<_InputIterator>::value_type,
+          typename _Allocator = allocator<_ValT>,
+          typename = _RequireInputIter<_InputIterator>,
+          typename = _RequireAllocator<_Allocator>>
+    vector(_InputIterator, _InputIterator, _Allocator = _Allocator())
+      -> vector<_ValT, _Allocator>;
+#endif
 
   /**
    *  @brief  Vector equality comparison.
diff --git a/libstdc++-v3/testsuite/23_containers/deque/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/deque/cons/deduction.cc
new file mode 100644 (file)
index 0000000..c7c0f2e
--- /dev/null
@@ -0,0 +1,70 @@
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++1z } }
+
+#include <deque>
+#include <testsuite_iterators.h>
+
+template<typename T>
+  using input_iterator_seq
+    = __gnu_test::test_container<T, __gnu_test::input_iterator_wrapper>;
+
+template<typename T, typename U> struct require_same;
+template<typename T> struct require_same<T, T> { using type = void; };
+
+template<typename T, typename U>
+  typename require_same<T, U>::type
+  check_type(U&) { }
+
+void
+test01()
+{
+  std::deque<unsigned> s0;
+
+  std::deque s1 = s0;
+  check_type<std::deque<unsigned>>(s1);
+
+  std::deque s2 = std::move(s0);
+  check_type<std::deque<unsigned>>(s2);
+
+  const std::deque s3 = s0;
+  check_type<const std::deque<unsigned>>(s3);
+
+  const std::deque s4 = s3;
+  check_type<const std::deque<unsigned>>(s4);
+}
+
+void
+test02()
+{
+  unsigned a[1] = {};
+  input_iterator_seq<unsigned> seq(a);
+
+  std::deque s1(seq.begin(), seq.end());
+  check_type<std::deque<unsigned>>(s1);
+
+  std::deque s2(seq.begin(), seq.end(), std::allocator<unsigned>());
+  check_type<std::deque<unsigned>>(s2);
+
+  std::deque s3(1U, 2L);
+  check_type<std::deque<long>>(s3);
+
+  std::deque s4(1U, 2L, std::allocator<long>());
+  check_type<std::deque<long>>(s4);
+}
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/forward_list/cons/deduction.cc
new file mode 100644 (file)
index 0000000..ee30288
--- /dev/null
@@ -0,0 +1,70 @@
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++1z } }
+
+#include <forward_list>
+#include <testsuite_iterators.h>
+
+template<typename T>
+  using input_iterator_seq
+    = __gnu_test::test_container<T, __gnu_test::input_iterator_wrapper>;
+
+template<typename T, typename U> struct require_same;
+template<typename T> struct require_same<T, T> { using type = void; };
+
+template<typename T, typename U>
+  typename require_same<T, U>::type
+  check_type(U&) { }
+
+void
+test01()
+{
+  std::forward_list<unsigned> s0;
+
+  std::forward_list s1 = s0;
+  check_type<std::forward_list<unsigned>>(s1);
+
+  std::forward_list s2 = std::move(s0);
+  check_type<std::forward_list<unsigned>>(s2);
+
+  const std::forward_list s3 = s0;
+  check_type<const std::forward_list<unsigned>>(s3);
+
+  const std::forward_list s4 = s3;
+  check_type<const std::forward_list<unsigned>>(s4);
+}
+
+void
+test02()
+{
+  unsigned a[1] = {};
+  input_iterator_seq<unsigned> seq(a);
+
+  std::forward_list s1(seq.begin(), seq.end());
+  check_type<std::forward_list<unsigned>>(s1);
+
+  std::forward_list s2(seq.begin(), seq.end(), std::allocator<unsigned>());
+  check_type<std::forward_list<unsigned>>(s2);
+
+  std::forward_list s3(1U, 2L);
+  check_type<std::forward_list<long>>(s3);
+
+  std::forward_list s4(1U, 2L, std::allocator<long>());
+  check_type<std::forward_list<long>>(s4);
+}
diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/list/cons/deduction.cc
new file mode 100644 (file)
index 0000000..c4df795
--- /dev/null
@@ -0,0 +1,70 @@
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++1z } }
+
+#include <list>
+#include <testsuite_iterators.h>
+
+template<typename T>
+  using input_iterator_seq
+    = __gnu_test::test_container<T, __gnu_test::input_iterator_wrapper>;
+
+template<typename T, typename U> struct require_same;
+template<typename T> struct require_same<T, T> { using type = void; };
+
+template<typename T, typename U>
+  typename require_same<T, U>::type
+  check_type(U&) { }
+
+void
+test01()
+{
+  std::list<unsigned> s0;
+
+  std::list s1 = s0;
+  check_type<std::list<unsigned>>(s1);
+
+  std::list s2 = std::move(s0);
+  check_type<std::list<unsigned>>(s2);
+
+  const std::list s3 = s0;
+  check_type<const std::list<unsigned>>(s3);
+
+  const std::list s4 = s3;
+  check_type<const std::list<unsigned>>(s4);
+}
+
+void
+test02()
+{
+  unsigned a[1] = {};
+  input_iterator_seq<unsigned> seq(a);
+
+  std::list s1(seq.begin(), seq.end());
+  check_type<std::list<unsigned>>(s1);
+
+  std::list s2(seq.begin(), seq.end(), std::allocator<unsigned>());
+  check_type<std::list<unsigned>>(s2);
+
+  std::list s3(1U, 2L);
+  check_type<std::list<long>>(s3);
+
+  std::list s4(1U, 2L, std::allocator<long>());
+  check_type<std::list<long>>(s4);
+}
diff --git a/libstdc++-v3/testsuite/23_containers/vector/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/vector/cons/deduction.cc
new file mode 100644 (file)
index 0000000..413f02c
--- /dev/null
@@ -0,0 +1,70 @@
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++1z } }
+
+#include <vector>
+#include <testsuite_iterators.h>
+
+template<typename T>
+  using input_iterator_seq
+    = __gnu_test::test_container<T, __gnu_test::input_iterator_wrapper>;
+
+template<typename T, typename U> struct require_same;
+template<typename T> struct require_same<T, T> { using type = void; };
+
+template<typename T, typename U>
+  typename require_same<T, U>::type
+  check_type(U&) { }
+
+void
+test01()
+{
+  std::vector<unsigned> s0;
+
+  std::vector s1 = s0;
+  check_type<std::vector<unsigned>>(s1);
+
+  std::vector s2 = std::move(s0);
+  check_type<std::vector<unsigned>>(s2);
+
+  const std::vector s3 = s0;
+  check_type<const std::vector<unsigned>>(s3);
+
+  const std::vector s4 = s3;
+  check_type<const std::vector<unsigned>>(s4);
+}
+
+void
+test02()
+{
+  unsigned a[1] = {};
+  input_iterator_seq<unsigned> seq(a);
+
+  std::vector s1(seq.begin(), seq.end());
+  check_type<std::vector<unsigned>>(s1);
+
+  std::vector s2(seq.begin(), seq.end(), std::allocator<unsigned>());
+  check_type<std::vector<unsigned>>(s2);
+
+  std::vector s3(1U, 2L);
+  check_type<std::vector<long>>(s3);
+
+  std::vector s4(1U, 2L, std::allocator<long>());
+  check_type<std::vector<long>>(s4);
+}