42 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef TEST_SUPPORT_COUNTING_PROJECTION_H10#define TEST_SUPPORT_COUNTING_PROJECTION_H11 12#include <functional>13#include <utility>14#include "test_macros.h"15 16#if TEST_STD_VER > 1417 18template <class Proj = std::identity>19class counting_projection {20 Proj proj_;21 int* count_ = nullptr;22 23public: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 35counting_projection(int& count) -> counting_projection<std::identity>;36template <class Proj>37counting_projection(Proj proj, int& count) -> counting_projection<Proj>;38 39#endif // TEST_STD_VER > 1440 41#endif // TEST_SUPPORT_COUNTING_PROJECTION_H42