Debian Codegraph @

libcxx/test/support/counting_projection.h

raw
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 TEST_SUPPORT_COUNTING_PROJECTION_H
10 #define TEST_SUPPORT_COUNTING_PROJECTION_H
11
12 #include <functional>
13 #include <utility>
14 #include "test_macros.h"
15
16 #if TEST_STD_VER > 14
17
18 template <class Proj = std::identity>
19 class counting_projection {
20 Proj proj_;
21 int* count_ = nullptr;
22
23 public:
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) {}
27
28 template <class T>
29 constexpr decltype(auto) operator()(T&& value) const {
30 ++(*count_);
31 return std::invoke(proj_, std::forward<T>(value));
32 }
33 };
34
35 counting_projection(int& count) -> counting_projection<std::identity>;
36 template <class Proj>
37 counting_projection(Proj proj, int& count) -> counting_projection<Proj>;
38
39 #endif // TEST_STD_VER > 14
40
41 #endif // TEST_SUPPORT_COUNTING_PROJECTION_H