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