
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](af65856eec
) * [basic_string](6d9f750dec
) * [array](0ca8c0895c
) * [deque](dbb6f8a817
) * [forward_list](e076700b77
) * [list](4a227e582b
) * [vector](df8f754792
) * [queue/stack/priority_queue](5b8b8b5dce
) * [basic_regex](edd5e29cfe
) * [optional](f35b4bc395
) * [map/multimap](edfe8525de
) * [set/multiset](e20865c387
) * [unordered_set/unordered_multiset](296a80102a
) * [unordered_map/unordered_multimap](dfcd4384cb
) * [function](e1eabcdfad
) * [tuple](1308011e1b
) * [shared_ptr/weak_ptr](83564056d4
) 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
79 lines
1.9 KiB
C++
79 lines
1.9 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <optional>
|
|
// UNSUPPORTED: c++03, c++11, c++14
|
|
|
|
// template<class T>
|
|
// optional(T) -> optional<T>;
|
|
|
|
#include <optional>
|
|
#include <cassert>
|
|
|
|
#include "test_macros.h"
|
|
|
|
struct A {};
|
|
|
|
int main(int, char**)
|
|
{
|
|
// Test the explicit deduction guides
|
|
{
|
|
// optional(T)
|
|
std::optional opt(5);
|
|
ASSERT_SAME_TYPE(decltype(opt), std::optional<int>);
|
|
assert(static_cast<bool>(opt));
|
|
assert(*opt == 5);
|
|
}
|
|
|
|
{
|
|
// optional(T)
|
|
std::optional opt(A{});
|
|
ASSERT_SAME_TYPE(decltype(opt), std::optional<A>);
|
|
assert(static_cast<bool>(opt));
|
|
}
|
|
|
|
{
|
|
// optional(const T&);
|
|
const int& source = 5;
|
|
std::optional opt(source);
|
|
ASSERT_SAME_TYPE(decltype(opt), std::optional<int>);
|
|
assert(static_cast<bool>(opt));
|
|
assert(*opt == 5);
|
|
}
|
|
|
|
{
|
|
// optional(T*);
|
|
const int* source = nullptr;
|
|
std::optional opt(source);
|
|
ASSERT_SAME_TYPE(decltype(opt), std::optional<const int*>);
|
|
assert(static_cast<bool>(opt));
|
|
assert(*opt == nullptr);
|
|
}
|
|
|
|
{
|
|
// optional(T[]);
|
|
int source[] = {1, 2, 3};
|
|
std::optional opt(source);
|
|
ASSERT_SAME_TYPE(decltype(opt), std::optional<int*>);
|
|
assert(static_cast<bool>(opt));
|
|
assert((*opt)[0] == 1);
|
|
}
|
|
|
|
// Test the implicit deduction guides
|
|
{
|
|
// optional(optional);
|
|
std::optional<char> source('A');
|
|
std::optional opt(source);
|
|
ASSERT_SAME_TYPE(decltype(opt), std::optional<char>);
|
|
assert(static_cast<bool>(opt) == static_cast<bool>(source));
|
|
assert(*opt == *source);
|
|
}
|
|
|
|
return 0;
|
|
}
|