From 225ab2b07b41d0f373efd574e962f90e8b73d46a Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Fri, 9 Jun 2017 12:04:53 +0100 Subject: [PATCH] Add deduction guides for sequence containers (P0433R2, partial) * 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 | 11 +++ libstdc++-v3/include/bits/forward_list.h | 10 +++ libstdc++-v3/include/bits/stl_deque.h | 9 +++ libstdc++-v3/include/bits/stl_list.h | 11 +++ libstdc++-v3/include/bits/stl_vector.h | 9 +++ .../23_containers/deque/cons/deduction.cc | 70 +++++++++++++++++++ .../forward_list/cons/deduction.cc | 70 +++++++++++++++++++ .../23_containers/list/cons/deduction.cc | 70 +++++++++++++++++++ .../23_containers/vector/cons/deduction.cc | 70 +++++++++++++++++++ 9 files changed, 330 insertions(+) create mode 100644 libstdc++-v3/testsuite/23_containers/deque/cons/deduction.cc create mode 100644 libstdc++-v3/testsuite/23_containers/forward_list/cons/deduction.cc create mode 100644 libstdc++-v3/testsuite/23_containers/list/cons/deduction.cc create mode 100644 libstdc++-v3/testsuite/23_containers/vector/cons/deduction.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6896c15fa6e..6909a1fe84a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,14 @@ +2017-06-09 Jonathan Wakely + + * 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 PR libstdc++/81017 diff --git a/libstdc++-v3/include/bits/forward_list.h b/libstdc++-v3/include/bits/forward_list.h index c37bf01345a..f319b7f0607 100644 --- a/libstdc++-v3/include/bits/forward_list.h +++ b/libstdc++-v3/include/bits/forward_list.h @@ -1359,6 +1359,16 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER } }; +#if __cpp_deduction_guides >= 201606 + template::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 diff --git a/libstdc++-v3/include/bits/stl_deque.h b/libstdc++-v3/include/bits/stl_deque.h index 6090635b7d6..e03e7f5808f 100644 --- a/libstdc++-v3/include/bits/stl_deque.h +++ b/libstdc++-v3/include/bits/stl_deque.h @@ -2242,6 +2242,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER #endif }; +#if __cpp_deduction_guides >= 201606 + template::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. diff --git a/libstdc++-v3/include/bits/stl_list.h b/libstdc++-v3/include/bits/stl_list.h index 0420dbfbba7..232885af79d 100644 --- a/libstdc++-v3/include/bits/stl_list.h +++ b/libstdc++-v3/include/bits/stl_list.h @@ -1867,6 +1867,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 } #endif }; + +#if __cpp_deduction_guides >= 201606 + template::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 /** diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index fb882126cf9..7ee3ce96890 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -1580,6 +1580,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER #endif }; +#if __cpp_deduction_guides >= 201606 + template::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 index 00000000000..c7c0f2e5ae1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/cons/deduction.cc @@ -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 +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++1z } } + +#include +#include + +template + using input_iterator_seq + = __gnu_test::test_container; + +template struct require_same; +template struct require_same { using type = void; }; + +template + typename require_same::type + check_type(U&) { } + +void +test01() +{ + std::deque s0; + + std::deque s1 = s0; + check_type>(s1); + + std::deque s2 = std::move(s0); + check_type>(s2); + + const std::deque s3 = s0; + check_type>(s3); + + const std::deque s4 = s3; + check_type>(s4); +} + +void +test02() +{ + unsigned a[1] = {}; + input_iterator_seq seq(a); + + std::deque s1(seq.begin(), seq.end()); + check_type>(s1); + + std::deque s2(seq.begin(), seq.end(), std::allocator()); + check_type>(s2); + + std::deque s3(1U, 2L); + check_type>(s3); + + std::deque s4(1U, 2L, std::allocator()); + check_type>(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 index 00000000000..ee30288678f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/cons/deduction.cc @@ -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 +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++1z } } + +#include +#include + +template + using input_iterator_seq + = __gnu_test::test_container; + +template struct require_same; +template struct require_same { using type = void; }; + +template + typename require_same::type + check_type(U&) { } + +void +test01() +{ + std::forward_list s0; + + std::forward_list s1 = s0; + check_type>(s1); + + std::forward_list s2 = std::move(s0); + check_type>(s2); + + const std::forward_list s3 = s0; + check_type>(s3); + + const std::forward_list s4 = s3; + check_type>(s4); +} + +void +test02() +{ + unsigned a[1] = {}; + input_iterator_seq seq(a); + + std::forward_list s1(seq.begin(), seq.end()); + check_type>(s1); + + std::forward_list s2(seq.begin(), seq.end(), std::allocator()); + check_type>(s2); + + std::forward_list s3(1U, 2L); + check_type>(s3); + + std::forward_list s4(1U, 2L, std::allocator()); + check_type>(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 index 00000000000..c4df79526a8 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/deduction.cc @@ -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 +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++1z } } + +#include +#include + +template + using input_iterator_seq + = __gnu_test::test_container; + +template struct require_same; +template struct require_same { using type = void; }; + +template + typename require_same::type + check_type(U&) { } + +void +test01() +{ + std::list s0; + + std::list s1 = s0; + check_type>(s1); + + std::list s2 = std::move(s0); + check_type>(s2); + + const std::list s3 = s0; + check_type>(s3); + + const std::list s4 = s3; + check_type>(s4); +} + +void +test02() +{ + unsigned a[1] = {}; + input_iterator_seq seq(a); + + std::list s1(seq.begin(), seq.end()); + check_type>(s1); + + std::list s2(seq.begin(), seq.end(), std::allocator()); + check_type>(s2); + + std::list s3(1U, 2L); + check_type>(s3); + + std::list s4(1U, 2L, std::allocator()); + check_type>(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 index 00000000000..413f02cc0cb --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/cons/deduction.cc @@ -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 +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++1z } } + +#include +#include + +template + using input_iterator_seq + = __gnu_test::test_container; + +template struct require_same; +template struct require_same { using type = void; }; + +template + typename require_same::type + check_type(U&) { } + +void +test01() +{ + std::vector s0; + + std::vector s1 = s0; + check_type>(s1); + + std::vector s2 = std::move(s0); + check_type>(s2); + + const std::vector s3 = s0; + check_type>(s3); + + const std::vector s4 = s3; + check_type>(s4); +} + +void +test02() +{ + unsigned a[1] = {}; + input_iterator_seq seq(a); + + std::vector s1(seq.begin(), seq.end()); + check_type>(s1); + + std::vector s2(seq.begin(), seq.end(), std::allocator()); + check_type>(s2); + + std::vector s3(1U, 2L); + check_type>(s3); + + std::vector s4(1U, 2L, std::allocator()); + check_type>(s4); +} -- 2.30.2