Quantify
An extensible C++ units library
Loading...
Searching...
No Matches
mul.cppm
Go to the documentation of this file.
1// Copyright (c) 2024-2025, Víctor Castillo Agüero.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16module;
18
19export module quantify.core:mul;
20import std;
21import :preface;
22import :frac;
23
24export namespace quantify {
25 template <typename... Products>
26 struct mul {
27 UNIT_SYMBOL(symbol_builder<Products...>::symbol())
28
29 private:
30 template <typename...>
31 struct symbol_builder {
33 };
34
35 template <typename P>
36 struct symbol_builder<P> {
37 UNIT_SYMBOL(P::symbol())
38 };
39
40 template <typename P, typename... Ps>
41 requires (sizeof...(Ps) > 0)
42 struct symbol_builder<P, Ps...> {
43 UNIT_SYMBOL(P::symbol() + "*" + symbol_builder<Ps...>::symbol())
44 };
45 };
46
47 template <typename... Products>
48 requires (has_scale_v<Products> && ...)
49 struct mul<Products...> {
50 using scale = mul<typename Products::scale...>;
51 // using reduce = typename ts::packs::flatten<mul<typename Products::reduce...>>::type;
52
53 template <typename T>
54 using factor = ratio<
55 T,
56 (long)(1 * ... * Products::template factor<T>::numerator),
57 (long)(1 * ... * Products::template factor<T>::denominator)
58 >;
59
60 UNIT_SYMBOL(symbol_builder<Products...>::symbol())
61
62 private:
63 template <typename...>
64 struct symbol_builder {
66 };
67
68 template <typename P>
69 struct symbol_builder<P> {
70 UNIT_SYMBOL(P::symbol())
71 };
72
73 template <typename P, typename... Ps>
74 requires (sizeof...(Ps) > 0)
75 struct symbol_builder<P, Ps...> {
76 UNIT_SYMBOL(P::symbol() + "*" + symbol_builder<Ps...>::symbol())
77 };
78 };
79}
#define UNIT_SYMBOL(...)
Definition unit_macros.h:18
Core components of the Quantify library.
constexpr bool has_scale_v
See has_scale.
Definition preface.cppm:103
ratio< T,(long)(1 *... *Products::template factor< T >::numerator),(long)(1 *... *Products::template factor< T >::denominator) > factor
Definition mul.cppm:54
mul< typename Products::scale... > scale
Definition mul.cppm:50
static constexpr std::string symbol() noexcept
Definition preface.cppm:33
Static representation of a numerical ratio in the form of a fraction.
Definition ratio.cppm:26
static constexpr T numerator
Definition ratio.cppm:27
static constexpr T denominator
Definition ratio.cppm:28