Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc++] P0433R2: add the remaining deduction guides.
Add deduction guides to `valarray` and `scoped_allocator_adaptor`. This largely finishes implementation of the paper: * deduction guides for other classes mentioned in the paper were implemented previously (see the list below); * deduction guides for several classes contained in the proposal (`reference_wrapper`, `lock_guard`, `scoped_lock`, `unique_lock`, `shared_lock`) were removed by [LWG2981](https://wg21.link/LWG2981). Also add deduction guides to the synopsis for the few classes (e.g. `pair`) where they were missing. The only part of the paper that isn't fully implemented after this patch is making sure certain deduction guides don't participate in overload resolution when given incorrect template parameters. List of significant commits implementing the other parts of P0433 (omitting some minor fixes): * [pair](af65856) * [basic_string](6d9f750) * [array](0ca8c08) * [deque](dbb6f8a) * [forward_list](e076700) * [list](4a227e5) * [vector](df8f754) * [queue/stack/priority_queue](5b8b8b5) * [basic_regex](edd5e29) * [optional](f35b4bc) * [map/multimap](edfe852) * [set/multiset](e20865c) * [unordered_set/unordered_multiset](296a801) * [unordered_map/unordered_multimap](dfcd438) * [function](e1eabcd) * [tuple](1308011) * [shared_ptr/weak_ptr](8356405) Additional notes: * It was revision 2 of the paper that was voted into the Standard. P0433R3 is a separate paper that is not part of the Standard. * The paper also mandates removing several `make_*_searcher` functions (e.g. `make_boyer_moore_searcher`) which are currently not implemented (except in `experimental/`). * The `__cpp_lib_deduction_guides` feature test macro from the paper was accidentally omitted from the Standard. Differential Revision: https://reviews.llvm.org/D112510
- Loading branch information
Showing
10 changed files
with
191 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
libcxx/test/std/numerics/numarray/template.valarray/valarray.cons/deduct.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++03, c++11, c++14 | ||
|
||
// <valarray> | ||
|
||
// template<class T, size_t cnt> valarray(const T(&)[cnt], size_t) -> valarray<T>; | ||
|
||
#include <valarray> | ||
|
||
#include "test_macros.h" | ||
|
||
int main(int, char**) | ||
{ | ||
{ | ||
// From (initializer_list<T>) | ||
std::valarray v = {1, 2, 3, 4, 5}; | ||
ASSERT_SAME_TYPE(decltype(v), std::valarray<int>); | ||
} | ||
|
||
{ | ||
// From (const T(&)[N], size_t) | ||
long a[] = {1, 2, 3, 4, 5}; | ||
std::valarray v(a, 5); | ||
ASSERT_SAME_TYPE(decltype(v), std::valarray<long>); | ||
} | ||
|
||
{ | ||
// From (const T&, size_t) | ||
long a[] = {1, 2, 3, 4, 5}; | ||
std::valarray v(&a[0], 5); | ||
// Surprising but true. | ||
ASSERT_SAME_TYPE(decltype(v), std::valarray<long*>); | ||
} | ||
|
||
{ | ||
// From (slice_array<T>) | ||
std::valarray<long> v{1,2,3,4,5}; | ||
std::valarray v2 = v[std::slice(2,3,1)]; | ||
static_assert(std::is_same_v<decltype(v2), std::valarray<long>>); | ||
} | ||
|
||
{ | ||
// From (gslice_array<T>) | ||
std::valarray<long> v{1,2,3,4,5}; | ||
std::valarray v2 = v[std::gslice(0, {5}, {1})]; | ||
static_assert(std::is_same_v<decltype(v2), std::valarray<long>>); | ||
} | ||
|
||
{ | ||
// From (mask_array<T>) | ||
std::valarray<long> v = {1, 2, 3, 4, 5}; | ||
std::valarray<bool> m = {true, false, true, false, true}; | ||
std::valarray v2 = v[m]; | ||
static_assert(std::is_same_v<decltype(v2), std::valarray<long>>); | ||
} | ||
|
||
{ | ||
// From (indirect_array<T>) | ||
std::valarray<long> v = {1, 2, 3, 4, 5}; | ||
std::valarray<size_t> i = {1, 2, 3}; | ||
std::valarray v2 = v[i]; | ||
static_assert(std::is_same_v<decltype(v2), std::valarray<long>>); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/deduct.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++03, c++11, c++14 | ||
|
||
// <scoped_allocator> | ||
|
||
// template<class _OuterAlloc, class... _InnerAllocs> | ||
// scoped_allocator_adaptor(_OuterAlloc, _InnerAllocs...) | ||
// -> scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...>; | ||
|
||
#include <scoped_allocator> | ||
|
||
#include "test_macros.h" | ||
#include "allocators.h" | ||
|
||
int main(int, char**) | ||
{ | ||
// Deduct from (const OuterAlloc&). | ||
{ | ||
typedef A1<int> OuterAlloc; | ||
OuterAlloc outer(3); | ||
std::scoped_allocator_adaptor a(outer); | ||
ASSERT_SAME_TYPE(decltype(a), std::scoped_allocator_adaptor<OuterAlloc>); | ||
} | ||
|
||
// Deduct from (OuterAlloc&&). | ||
{ | ||
typedef A1<int> OuterAlloc; | ||
std::scoped_allocator_adaptor a(OuterAlloc(3)); | ||
ASSERT_SAME_TYPE(decltype(a), std::scoped_allocator_adaptor<OuterAlloc>); | ||
} | ||
|
||
// Deduct from (const OuterAlloc&, const InnerAlloc&). | ||
{ | ||
typedef A1<int> OuterAlloc; | ||
typedef A2<int> InnerAlloc; | ||
OuterAlloc outer(3); | ||
InnerAlloc inner(4); | ||
|
||
std::scoped_allocator_adaptor a(outer, inner); | ||
ASSERT_SAME_TYPE(decltype(a), std::scoped_allocator_adaptor<OuterAlloc, InnerAlloc>); | ||
} | ||
|
||
// Deduct from (const OuterAlloc&, const InnerAlloc1&, InnerAlloc2&&). | ||
{ | ||
typedef A1<int> OuterAlloc; | ||
typedef A2<int> InnerAlloc1; | ||
typedef A2<float> InnerAlloc2; | ||
OuterAlloc outer(3); | ||
InnerAlloc1 inner(4); | ||
|
||
std::scoped_allocator_adaptor a(outer, inner, InnerAlloc2(5)); | ||
ASSERT_SAME_TYPE( | ||
decltype(a), std::scoped_allocator_adaptor<OuterAlloc, InnerAlloc1, InnerAlloc2>); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters