ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
ratio.hpp
1// This file is part of the ACTS project.
2//
3// Copyright (C) 2016 CERN for the benefit of the ACTS project
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9#pragma once
10
11// System include(s)
12#include <ratio>
13
14namespace detray {
15
18template <typename... ratios>
20
22template <typename R>
25 using ratio = R;
26};
27
29template <typename ratio1, typename ratio2, typename... ratios>
30struct ratio_sum_helper<ratio1, ratio2, ratios...> {
32 using first_two_sum = std::ratio_add<ratio1, ratio2>;
33
36
37 // recursive summation of first two std::ratio
39 using ratio =
40 typename std::conditional_t<sizeof...(ratios) == 0, first_two_sum,
41 typename next_helper::ratio>;
42};
43
44
46template <typename... ratios>
47struct ratio_sum {
49 using helper = ratio_sum_helper<ratios...>;
51 using ratio = typename helper::ratio;
52};
53
55template <typename R>
58 static constexpr bool value = (R::num == R::den);
59};
60
62template <class R>
63inline constexpr bool is_ratio_one_v = is_ratio_one<R>::value;
64
65} // namespace detray
Detray include(s).
Definition array_operators.hpp:18
constexpr bool is_ratio_one_v
True when the supplied ratio is exactly one.
Definition ratio.hpp:63
Helper trait to check if the ratio is one.
Definition ratio.hpp:56
static constexpr bool value
Whether the ratio's numerator and denominator are equal.
Definition ratio.hpp:58
R ratio
The sole ratio, unchanged.
Definition ratio.hpp:25
typename std::conditional_t< sizeof...(ratios)==0, first_two_sum, typename next_helper::ratio > ratio
Result of adding all ratios in the parameter pack.
Definition ratio.hpp:39
ratio_sum_helper< first_two_sum, ratios... > next_helper
Recursive helper used to add any remaining ratios.
Definition ratio.hpp:35
std::ratio_add< ratio1, ratio2 > first_two_sum
Sum of the first two ratios before folding in the remainder.
Definition ratio.hpp:32
Helper struct to sum over variadic std::ratio.
Definition ratio.hpp:19
Struct to sum over variadic std::ratio.
Definition ratio.hpp:47
ratio_sum_helper< ratios... > helper
Helper that performs the recursive sum.
Definition ratio.hpp:49
typename helper::ratio ratio
The exact rational sum of all input ratios.
Definition ratio.hpp:51