GCC Code Coverage Report


Directory: include/kumi/
File: include/kumi/functional/functors.hpp
Date: 2026-10-14 16:33:56
Exec Total Coverage
Lines: 11 11 100.0%
Functions: 465 465 100.0%
Branches: 19 28 67.9%

Line Branch Exec Source
1 //======================================================================================================================
2 /*
3 KUMI - Compact Tuple Tools
4 Copyright : KUMI Project Contributors
5 SPDX-License-Identifier: BSL-1.0
6 */
7 //======================================================================================================================
8 #pragma once
9
10 namespace kumi
11 {
12 namespace function
13 {
14 struct identity_t
15 {
16 130 template<typename T> KUMI_ABI constexpr T&& operator()(T&& t) const noexcept { return KUMI_FWD(t); }
17 };
18
19 KUMI_VARIABLE_ABI constexpr identity_t identity;
20
21 struct max_t
22 {
23 template<typename T, typename U>
24 KUMI_ABI constexpr decltype(auto) operator()(T&& t, U&& u) const noexcept(noexcept(KUMI_FWD(t) > KUMI_FWD(u)))
25 requires requires { KUMI_FWD(t) > KUMI_FWD(u); }
26 {
27
10/14
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 38 times.
✓ Branch 9 taken 28 times.
✓ Branch 10 taken 8 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 4 times.
120 return KUMI_FWD(t) > KUMI_FWD(u) ? KUMI_FWD(t) : KUMI_FWD(u);
28 }
29 };
30
31 KUMI_VARIABLE_ABI constexpr max_t max;
32
33 struct min_t
34 {
35 template<typename T, typename U>
36 KUMI_ABI constexpr decltype(auto) operator()(T&& t, U&& u) const noexcept(noexcept(KUMI_FWD(t) < KUMI_FWD(u)))
37 requires requires { KUMI_FWD(t) < KUMI_FWD(u); }
38 {
39
9/14
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 22 times.
✓ Branch 11 taken 29 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 4 times.
105 return KUMI_FWD(t) < KUMI_FWD(u) ? KUMI_FWD(t) : KUMI_FWD(u);
40 }
41 };
42
43 KUMI_VARIABLE_ABI constexpr min_t min;
44
45 struct adressof_t
46 {
47 template<typename T>
48 requires(std::is_object_v<T>)
49 KUMI_ABI constexpr T* operator()(T& t) const noexcept(noexcept(&t))
50 {
51 // This is invalid for overloaded operator&
52 22 return &t;
53 }
54
55 template<typename T> constexpr T const* operator()(T const&&) = delete;
56 };
57
58 KUMI_VARIABLE_ABI constexpr adressof_t adressof;
59 }
60
61 namespace _
62 {
63 template<typename T, typename> extern T common_product_type;
64
65 template<typename T, std::size_t... I>
66 extern kumi::common_product_type_t<std::remove_cvref_t<kumi::element_t<I, T>>...>
67 common_product_type<T, std::index_sequence<I...>>;
68
69 template<typename T> using common_product_type_t = decltype(common_product_type<T, kumi::function::indexes_for<T>>);
70
71 struct builder_t
72 {
73 template<kumi::concepts::product_type T, std::size_t... I>
74 1008 KUMI_HIDDEN_ABI constexpr auto operator()(T&& t, std::index_sequence<I...>) const
75 {
76 using res_t = kumi::builder_make_t<T, kumi::element_t<I, T>...>;
77 3262 return res_t{get<I>(KUMI_FWD(t))...};
78 }
79
80 template<typename T, std::size_t N, std::size_t... I>
81 156 KUMI_HIDDEN_ABI constexpr auto operator()(T&& t,
82 std::integral_constant<std::size_t, N>,
83 std::index_sequence<I...>) const
84 {
85 using U = kumi::_::common_product_type_t<T>;
86 using res_t = kumi::builder_make_t<U, kumi::element_t<N, kumi::element_t<I, T>>...>;
87 960 return res_t{get<N>(get<I>(KUMI_FWD(t)))...};
88 }
89
90 template<typename T, std::size_t... E, std::size_t... I>
91 270 KUMI_HIDDEN_ABI constexpr auto operator()(T&& t, std::index_sequence<E...>, std::index_sequence<I...>) const
92 {
93 using U = kumi::_::common_product_type_t<T>;
94 using res_t = kumi::builder_make_t<U, kumi::element_t<E, kumi::element_t<I, T>>...>;
95 1520 return res_t{get<E>(get<I>(KUMI_FWD(t)))...};
96 308 }
97 };
98
99 KUMI_VARIABLE_ABI constexpr builder_t builder{};
100 }
101 }
102