1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef TEST_SUPPORT_COUNTING_PROJECTION_H
10 #define TEST_SUPPORT_COUNTING_PROJECTION_H
14 #include "test_macros.h"
18 template <class Proj
= std::identity
>
19 class counting_projection
{
21 int* count_
= nullptr;
24 constexpr counting_projection() = default;
25 constexpr counting_projection(int& count
) : count_(&count
) {}
26 constexpr counting_projection(Proj proj
, int& count
) : proj_(std::move(proj
)), count_(&count
) {}
29 constexpr decltype(auto) operator()(T
&& value
) const {
31 return std::invoke(proj_
, std::forward
<T
>(value
));
35 counting_projection(int& count
) -> counting_projection
<std::identity
>;
37 counting_projection(Proj proj
, int& count
) -> counting_projection
<Proj
>;
39 #endif // TEST_STD_VER > 14
41 #endif // TEST_SUPPORT_COUNTING_PROJECTION_H