mimic++ v9.2.1
Loading...
Searching...
No Matches
GeneralPolicies.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_POLICIES_GENERAL_POLICIES_HPP
7#define MIMICPP_POLICIES_GENERAL_POLICIES_HPP
8
9#pragma once
10
11#include "mimic++/Fwd.hpp"
15
16#ifndef MIMICPP_DETAIL_IS_MODULE
17 #include <iterator>
18 #include <utility>
19#endif
20
21namespace mimicpp::detail
22{
23 [[nodiscard]]
24 constexpr bool is_matching(const Constness lhs, const Constness rhs) noexcept
25 {
26 return std::cmp_not_equal(0, util::to_underlying(lhs) & util::to_underlying(rhs));
27 }
28
29 [[nodiscard]]
30 constexpr bool is_matching(const ValueCategory lhs, const ValueCategory rhs) noexcept
31 {
32 return std::cmp_not_equal(0, util::to_underlying(lhs) & util::to_underlying(rhs));
33 }
34}
35
37{
39 {
40 public:
41 template <typename Return, typename... Args>
42 static constexpr void finalize_call(const call::Info<Return, Args...>&) noexcept
43 {
44 }
45 };
46
47 template <ValueCategory expected>
49 {
50 public:
51 [[nodiscard]]
52 static constexpr bool is_satisfied() noexcept
53 {
54 return true;
55 }
56
57 template <typename Return, typename... Args>
58 [[nodiscard]]
59 static constexpr bool matches(const call::Info<Return, Args...>& info) noexcept
60 {
61 return mimicpp::detail::is_matching(info.fromCategory, expected);
62 }
63
64 template <typename Return, typename... Args>
65 static constexpr void consume([[maybe_unused]] const call::Info<Return, Args...>& info) noexcept
66 {
67 MIMICPP_ASSERT(mimicpp::detail::is_matching(info.fromCategory, expected), "Call does not match.");
68 }
69
70 [[nodiscard]]
71 static auto describe()
72 {
73 if constexpr (ValueCategory::any != expected)
74 {
75 StringStreamT stream{};
76 stream << "expect: from ";
77 mimicpp::print(std::ostreambuf_iterator{stream}, expected);
78 stream << " category overload";
79
80 return std::move(stream).str();
81 }
82 else
83 {
84 return std::nullopt;
85 }
86 }
87 };
88
89 template <Constness constness>
91 {
92 public:
93 [[nodiscard]]
94 static constexpr bool is_satisfied() noexcept
95 {
96 return true;
97 }
98
99 template <typename Return, typename... Args>
100 [[nodiscard]]
101 static constexpr bool matches(const call::Info<Return, Args...>& info) noexcept
102 {
103 return mimicpp::detail::is_matching(info.fromConstness, constness);
104 }
105
106 template <typename Return, typename... Args>
107 static constexpr void consume([[maybe_unused]] const call::Info<Return, Args...>& info) noexcept
108 {
109 MIMICPP_ASSERT(mimicpp::detail::is_matching(info.fromConstness, constness), "Call does not match.");
110 }
111
112 [[nodiscard]]
113 static auto describe()
114 {
115 if constexpr (mimicpp::Constness::any != constness)
116 {
117 StringStreamT stream{};
118 stream << "expect: from ";
119 mimicpp::print(std::ostreambuf_iterator{stream}, constness);
120 stream << " qualified overload";
121
122 return std::move(stream).str();
123 }
124 else
125 {
126 return std::nullopt;
127 }
128 }
129 };
130}
131
132#endif
#define MIMICPP_ASSERT(condition, msg)
Definition Config.hpp:51
Definition Call.hpp:27
Definition GeneralPolicies.hpp:49
static constexpr bool is_satisfied() noexcept
Definition GeneralPolicies.hpp:52
static constexpr void consume(const call::Info< Return, Args... > &info) noexcept
Definition GeneralPolicies.hpp:65
static auto describe()
Definition GeneralPolicies.hpp:71
static constexpr bool matches(const call::Info< Return, Args... > &info) noexcept
Definition GeneralPolicies.hpp:59
Definition GeneralPolicies.hpp:91
static constexpr bool is_satisfied() noexcept
Definition GeneralPolicies.hpp:94
static auto describe()
Definition GeneralPolicies.hpp:113
static constexpr void consume(const call::Info< Return, Args... > &info) noexcept
Definition GeneralPolicies.hpp:107
static constexpr bool matches(const call::Info< Return, Args... > &info) noexcept
Definition GeneralPolicies.hpp:101
Definition GeneralPolicies.hpp:39
static constexpr void finalize_call(const call::Info< Return, Args... > &) noexcept
Definition GeneralPolicies.hpp:42
constexpr printing::PrintFn print
Functional object, converting the given object to its textual representation.
Definition Print.hpp:183
Definition ArgRequirementPolicies.hpp:28
constexpr std::underlying_type_t< T > to_underlying(T const value) noexcept
Definition C++23Backports.hpp:62
ValueCategory
Definition Fwd.hpp:34
@ any
Definition Fwd.hpp:37
std::basic_ostringstream< CharT, CharTraitsT > StringStreamT
Definition Format.hpp:35
Constness
Definition Fwd.hpp:27
@ any
Definition Fwd.hpp:30