[flang][runtime] Make defined formatted I/O process format elementally (#74150)
[llvm-project.git] / libcxx / test / support / counting_projection.h
blob1af2c80f244d85e502d2faa60189b4afdc3c6f92
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 //===----------------------------------------------------------------------===//
9 #ifndef TEST_SUPPORT_COUNTING_PROJECTION_H
10 #define TEST_SUPPORT_COUNTING_PROJECTION_H
12 #include <functional>
13 #include <utility>
14 #include "test_macros.h"
16 #if TEST_STD_VER > 14
18 template <class Proj = std::identity>
19 class counting_projection {
20 Proj proj_;
21 int* count_ = nullptr;
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) {}
28 template <class T>
29 constexpr decltype(auto) operator()(T&& value) const {
30 ++(*count_);
31 return std::invoke(proj_, std::forward<T>(value));
35 counting_projection(int& count) -> counting_projection<std::identity>;
36 template <class Proj>
37 counting_projection(Proj proj, int& count) -> counting_projection<Proj>;
39 #endif // TEST_STD_VER > 14
41 #endif // TEST_SUPPORT_COUNTING_PROJECTION_H