xref: /llvm-project/libcxx/test/support/unwrap_container_adaptor.h (revision 87f3ff3e55e67709c3455a7ba105424be8ae84f2)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef SUPPORT_UNWRAP_CONTAINER_ADAPTOR_H
10 #define SUPPORT_UNWRAP_CONTAINER_ADAPTOR_H
11 
12 // Allows accessing the underlying container of the given adaptor.
13 template <class Adaptor>
14 struct UnwrapAdaptor : Adaptor {
15   UnwrapAdaptor() = default;
16 
UnwrapAdaptorUnwrapAdaptor17   UnwrapAdaptor(Adaptor&& adaptor) : Adaptor(std::move(adaptor)) {}
18   // `c` is a protected member variable of the base class.
get_containerUnwrapAdaptor19   decltype(auto) get_container() {
20     return (UnwrapAdaptor::c); // Put into parentheses to make sure the function returns a reference.
21   }
22 
23   // TODO: make this work pre-C++20.
get_comparatorUnwrapAdaptor24   decltype(auto) get_comparator()
25   requires requires {
26     UnwrapAdaptor::c;
27   } {
28     return (UnwrapAdaptor::comp); // Put into parentheses to make sure the function returns a reference.
29   }
30 };
31 
32 #endif // SUPPORT_UNWRAP_CONTAINER_ADAPTOR_H
33