mimic++ v6
Loading...
Searching...
No Matches
Common.hpp
Go to the documentation of this file.
1// Copyright Dominic (DNKpp) Koepke 2024 - 2025.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at
4// https://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef MIMICPP_MATCHERS_COMMON_HPP
7#define MIMICPP_MATCHERS_COMMON_HPP
8
9#pragma once
10
11#include "mimic++/Fwd.hpp"
12#include "mimic++/Printer.hpp"
13#include "mimic++/Utility.hpp"
14
15#include <concepts>
16#include <type_traits>
17
19{
20 template <typename Matcher>
22}
23
24namespace mimicpp::detail::matches_hook
25{
26 template <typename Matcher, typename T, typename... Others>
27 [[nodiscard]]
28 constexpr bool matches_impl(
29 [[maybe_unused]] const priority_tag<1>,
30 const Matcher& matcher,
31 T& target,
32 Others&... others)
33 requires requires {
34 {
35 custom::matcher_traits<Matcher>{}.matches(matcher, target, others...)
36 } -> std::convertible_to<bool>;
37 }
38 {
39 return custom::matcher_traits<Matcher>{}.matches(matcher, target, others...);
40 }
41
42 template <typename Matcher, typename T, typename... Others>
43 [[nodiscard]]
44 constexpr bool matches_impl(
45 [[maybe_unused]] const priority_tag<0>,
46 const Matcher& matcher,
47 T& target,
48 Others&... others)
49 requires requires { { matcher.matches(target, others...) } -> std::convertible_to<bool>; }
50 {
51 return matcher.matches(target, others...);
52 }
53
54 constexpr priority_tag<1> maxTag;
55
56 constexpr auto matches = []<typename Matcher, typename T, typename... Others>(
57 const Matcher& matcher,
58 T& target,
59 Others&... others)
60 requires requires {
61 {
62 matches_impl(maxTag, matcher, target, others...)
63 }-> std::convertible_to<bool>; }
64 {
65 return matches_impl(maxTag, matcher, target, others...);
66 };
67}
68
69namespace mimicpp::detail::describe_hook
70{
71 template <typename Matcher>
72 [[nodiscard]]
73 constexpr decltype(auto) describe_impl(
74 const Matcher& matcher,
75 [[maybe_unused]] const priority_tag<1>)
76 requires requires {
77 {
78 custom::matcher_traits<Matcher>{}.describe(matcher)
79 } -> std::convertible_to<StringViewT>;
80 }
81 {
82 return custom::matcher_traits<Matcher>{}.describe(matcher);
83 }
84
85 template <typename Matcher>
86 [[nodiscard]]
87 constexpr decltype(auto) describe_impl(
88 const Matcher& matcher,
89 [[maybe_unused]] const priority_tag<0>)
90 requires requires { { matcher.describe() } -> std::convertible_to<StringViewT>; }
91 {
92 return matcher.describe();
93 }
94
95 constexpr priority_tag<1> maxTag;
96
97 constexpr auto describe = []<typename Matcher>(const Matcher& matcher) -> decltype(auto)
98 requires requires { { describe_impl(matcher, maxTag) } -> std::convertible_to<StringViewT>; }
99 {
100 return describe_impl(matcher, maxTag);
101 };
102}
103
104namespace mimicpp
105{
106 template <typename T, typename First, typename... Others>
107 concept matcher_for = std::same_as<T, std::remove_cvref_t<T>>
108 && std::is_move_constructible_v<T>
109 && std::destructible<T>
110 && requires(const T& matcher, First& first, Others&... others) {
111 { detail::matches_hook::matches(matcher, first, others...) } -> std::convertible_to<bool>;
112 { detail::describe_hook::describe(matcher) } -> std::convertible_to<StringViewT>;
113 };
114}
115
116#endif
Definition Common.hpp:107
Definition Common.hpp:19
Definition BoostTest.hpp:20
Definition Common.hpp:21
Definition Utility.hpp:33