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
This commit is contained in:
Jonathan Wakely 2017-06-09 12:04:53 +01:00 committed by Jonathan Wakely
parent 01a8cacc96
commit 225ab2b07b
9 changed files with 330 additions and 0 deletions

View 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

View 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

View 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.

View 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
/**

View 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.

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}