-
Notifications
You must be signed in to change notification settings - Fork 78
/
quantity_spec.h
1413 lines (1289 loc) · 66.6 KB
/
quantity_spec.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// The MIT License (MIT)
//
// Copyright (c) 2018 Mateusz Pusz
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#pragma once
#include <mp_units/bits/algorithm.h>
#include <mp_units/bits/expression_template.h>
#include <mp_units/bits/external/type_name.h>
#include <mp_units/bits/external/type_traits.h>
#include <mp_units/bits/get_common_base.h>
#include <mp_units/bits/quantity_concepts.h>
#include <mp_units/bits/quantity_spec_concepts.h>
#include <mp_units/bits/reference_concepts.h>
#include <mp_units/bits/representation_concepts.h>
#include <mp_units/dimension.h>
#include <tuple>
namespace mp_units {
namespace detail {
// TODO revise the note in the below comment
/**
* @brief Returns the most restrictive character from the list
*
* @note `vector * vector` returns vector (not tensor)
*/
template<std::same_as<quantity_character>... Ts>
[[nodiscard]] consteval quantity_character common_quantity_character(Ts... args)
{
return max({args...});
}
template<typename... Qs1, typename... Qs2>
[[nodiscard]] consteval quantity_character derived_quantity_character(const type_list<Qs1...>&,
const type_list<Qs2...>&)
{
constexpr quantity_character num =
common_quantity_character(quantity_character::scalar, expr_type<Qs1>::character...);
constexpr quantity_character den =
common_quantity_character(quantity_character::scalar, expr_type<Qs2>::character...);
if constexpr (num == den)
return quantity_character::scalar;
else
return common_quantity_character(num, den);
}
/**
* @brief Initializes quantity character
*
* If a quantity character value is present in template parameters, this value will be used.
* Otherwise, an inherited/derived value provided through the function argument is returned.
*/
template<auto... Args>
[[nodiscard]] consteval quantity_character quantity_character_init(quantity_character ch)
{
if constexpr (contains<quantity_character, Args...>())
return get<quantity_character, Args...>();
else
return ch;
}
template<NamedQuantitySpec Lhs, NamedQuantitySpec Rhs>
struct quantity_spec_less : std::bool_constant<type_name<Lhs>() < type_name<Rhs>()> {};
template<typename T1, typename T2>
using type_list_of_quantity_spec_less = expr_less<T1, T2, quantity_spec_less>;
template<NamedQuantitySpec Q>
requires requires { Q::dimension; }
using to_dimension = std::remove_const_t<decltype(Q::dimension)>;
template<AssociatedUnit U>
[[nodiscard]] consteval auto get_associated_quantity(U);
#ifndef __cpp_explicit_this_parameter
template<typename Self>
#endif
struct quantity_spec_interface {
#ifdef __cpp_explicit_this_parameter
template<typename Self, AssociatedUnit U>
[[nodiscard]] consteval Reference auto operator[](this Self self, U u) const
requires(implicitly_convertible(self, detail::get_associated_quantity(u)))
{
return reference<self, u>{};
}
template<typename Self, typename Q>
[[nodiscard]] constexpr Quantity auto operator()(this Self self, Q&& q) const
requires Quantity<std::remove_cvref_t<Q>> && (explicitly_convertible(std::remove_cvref_t<Q>::quantity_spec, self))
{
return std::forward<Q>(q).number() * reference<self, std::remove_cvref_t<Q>::unit>{};
}
#else
template<AssociatedUnit U>
[[nodiscard]] consteval Reference auto operator[](U u) const
requires(implicitly_convertible(Self{}, detail::get_associated_quantity(u)))
{
return reference<Self{}, u>{};
}
template<typename Q>
requires Quantity<std::remove_cvref_t<Q>> && (explicitly_convertible(std::remove_cvref_t<Q>::quantity_spec, Self{}))
[[nodiscard]] constexpr Quantity auto operator()(Q&& q) const
{
return std::forward<Q>(q).number() * reference<Self{}, std::remove_cvref_t<Q>::unit>{};
}
#endif
};
} // namespace detail
/**
* @brief Quantity Specification
*
* This type specifies all the properties of a quantity and allow modeling most of the quantities in the ISO 80000.
* It serves to define base and derived quantities as well as quantity kinds. Each quantity specification
* provides an information on how this quantity relates to other quantities, specifies its dimension, and character.
*
* Quantity character can be derived from other quantities or explicitly overriden through a template parameter.
*
* Binding a proper unit to a quantity specification via an indexing operator (`operator[]`) results
* in a quantity reference.
*
* Call operator may be used to change the type of a provided quantity.
*
* Two quantity specifications are deemed equal when they are of the same type. With that, both strong
* types `speed` and `velocity` are considered not equal to `derived_dimension<length, per<time>>` or
* to each other.
*/
#ifdef __cpp_explicit_this_parameter
template<auto...>
#else
template<typename, auto...>
#endif
struct quantity_spec;
inline constexpr struct is_kind {
} is_kind;
/**
* @brief Specialization defining a base quantity
*
* Base quantity is a quantity in a conventionally chosen subset of a given system of quantities, where no quantity
* in the subset can be expressed in terms of the other quantities within that subset. They are referred to as
* being mutually independent since a base quantity cannot be expressed as a product of powers of the other base
* quantities.
*
* This quantity serves as a root/kind for a new hierarchy of quantities of the same kind.
*
* Base quantities have scalar character by default.
*
* User should derive a strong type from this class template rather than use it directly in the source code.
* For example:
*
* @code{.cpp}
* inline constexpr struct dim_length : base_dimension<"L"> {} dim_length;
* inline constexpr struct dim_mass : base_dimension<"M"> {} dim_mass;
* inline constexpr struct dim_time : base_dimension<"T"> {} dim_time;
*
* inline constexpr struct length : quantity_spec<dim_length> {} length;
* inline constexpr struct mass : quantity_spec<dim_mass> {} mass;
* inline constexpr struct time : quantity_spec<dim_time> {} time;
* @endcode
*
* @note A common convention in this library is to assign the same name for a type and an object of this type.
* Besides defining them user never works with the types in the source code. All operations
* are done on the objects. Contrarily, the types are the only one visible in the compilation
* errors. Having them of the same names improves user experience and somehow blurs those separate domains.
*
* @tparam BaseDimension base dimension for which a base quantity is being defined
* @tparam Args optionally a value of a `quantity_character` in case the base quantity should not be scalar
*/
#ifdef __cpp_explicit_this_parameter
template<BaseDimension auto Dim, one_of<quantity_character> auto... Args>
requires(... && !QuantitySpec<std::remove_const_t<decltype(Args)>>)
struct quantity_spec<Dim, Args...> : detail::quantity_spec_interface {
#else
template<typename Self, BaseDimension auto Dim, one_of<quantity_character> auto... Args>
requires(... && !QuantitySpec<std::remove_const_t<decltype(Args)>>)
struct quantity_spec<Self, Dim, Args...> : detail::quantity_spec_interface<Self> {
#endif
static constexpr BaseDimension auto dimension = Dim;
static constexpr quantity_character character = detail::quantity_character_init<Args...>(quantity_character::scalar);
};
/**
* @brief Specialization defining a named quantity being the result of a quantity calculus
*
* Derived quantity is a quantity, in a system of quantities, defined in terms of other quantities
* of that system.
*
* This quantity serves as a root/kind for a new hierarchy of quantities of the same kind.
*
* Such quantities by default derive the character from the derived quantity definition.
*
* User should derive a strong type from this class template rather than use it directly in the source code.
* For example:
*
* @code{.cpp}
* inline constexpr struct area : quantity_spec<pow<2>(length)> {} area;
* inline constexpr struct volume : quantity_spec<pow<3>(length)> {} volume;
* inline constexpr struct velocity : quantity_spec<position_vector / duration> {} velocity;
* inline constexpr struct speed : quantity_spec<length / time> {} speed;
* inline constexpr struct force : quantity_spec<mass * acceleration, quantity_character::vector> {} force;
* inline constexpr struct power : quantity_spec<force * velocity, quantity_character::scalar> {} power;
* @endcode
*
* @note A common convention in this library is to assign the same name for a type and an object of this type.
* Besides defining them user never works with the types in the source code. All operations
* are done on the objects. Contrarily, the types are the only one visible in the compilation
* errors. Having them of the same names improves user experience and somehow blurs those separate domains.
*
* @tparam Eq quantity equation specification of a derived quantity
* @tparam Args optionally a value of a `quantity_character` in case the base quantity should not be scalar
*/
#ifdef __cpp_explicit_this_parameter
template<detail::IntermediateDerivedQuantitySpec auto Eq, one_of<quantity_character> auto... Args>
requires(... && !QuantitySpec<std::remove_const_t<decltype(Args)>>)
struct quantity_spec<Eq, Args...> : detail::quantity_spec_interface {
#else
template<typename Self, detail::IntermediateDerivedQuantitySpec auto Eq, one_of<quantity_character> auto... Args>
requires(... && !QuantitySpec<std::remove_const_t<decltype(Args)>>)
struct quantity_spec<Self, Eq, Args...> : detail::quantity_spec_interface<Self> {
#endif
static constexpr auto _equation_ = Eq;
static constexpr Dimension auto dimension = Eq.dimension;
static constexpr quantity_character character = detail::quantity_character_init<Args...>(Eq.character);
};
/**
* @brief Specialization defining a leaf quantity in the hierarchy
*
* Quantities of the same kind form a hierarchy. This specialization adds new leaf to such a tree which
* can later be used as a parent by other quantities.
*
* The character of those quantities by default is derived from the parent quantity.
*
* User should derive a strong type from this class template rather than use it directly in the source code.
* For example:
*
* @code{.cpp}
* inline constexpr struct width : quantity_spec<length> {} width;
* inline constexpr struct height : quantity_spec<length> {} height;
* inline constexpr struct diameter : quantity_spec<width> {} diameter;
* inline constexpr struct position_vector : quantity_spec<length, quantity_character::vector> {} position_vector;
* @endcode
*
* @note A common convention in this library is to assign the same name for a type and an object of this type.
* Besides defining them user never works with the types in the source code. All operations
* are done on the objects. Contrarily, the types are the only one visible in the compilation
* errors. Having them of the same names improves user experience and somehow blurs those separate domains.
*
* @tparam Q quantity specification of a parent quantity
* @tparam Args optionally a value of a `quantity_character` in case the base quantity should not be scalar
* or `is_kind` in case the quantity starts a new hierarchy tree of a kind
*/
#ifdef __cpp_explicit_this_parameter
template<detail::NamedQuantitySpec auto QS, one_of<quantity_character, struct is_kind> auto... Args>
requires(... && !QuantitySpec<std::remove_const_t<decltype(Args)>>)
struct quantity_spec<QS, Args...> : std::remove_const_t<decltype(QS)> {
#else
template<typename Self, detail::NamedQuantitySpec auto QS, one_of<quantity_character, struct is_kind> auto... Args>
requires(... && !QuantitySpec<std::remove_const_t<decltype(Args)>>)
struct quantity_spec<Self, QS, Args...> : std::remove_const_t<decltype(QS)> {
#endif
static constexpr auto _parent_ = QS;
static constexpr quantity_character character = detail::quantity_character_init<Args...>(QS.character);
#ifndef __cpp_explicit_this_parameter
template<AssociatedUnit U>
[[nodiscard]] consteval Reference auto operator[](U u) const
requires(implicitly_convertible(Self{}, detail::get_associated_quantity(u)))
{
return reference<Self{}, u>{};
}
template<typename Q>
requires Quantity<std::remove_cvref_t<Q>> && (explicitly_convertible(std::remove_cvref_t<Q>::quantity_spec, Self{}))
[[nodiscard]] constexpr Quantity auto operator()(Q&& q) const
{
return std::forward<Q>(q).number() * reference<Self{}, std::remove_cvref_t<Q>::unit>{};
}
#endif
};
/**
* @brief Specialization defining a leaf derived quantity in the hierarchy and refining paren't equation
*
* Quantities of the same kind form a hierarchy. This specialization adds new leaf to such a tree which
* can later be used as a parent by other quantities. Additionally, this defintion adds additional
* constraints on the derived quantity's equation.
*
* The character of those quantities by default is derived from the parent quantity.
*
* User should derive a strong type from this class template rather than use it directly in the source code.
* For example:
*
* @code{.cpp}
* inline constexpr struct velocity : quantity_spec<speed, position_vector / duration> {} velocity;
* inline constexpr struct weight : quantity_spec<force, mass * acceleration_of_free_fall> {} weight;
* inline constexpr struct kinetic_energy : quantity_spec<mechanical_energy, mass * pow<2>(speed)> {} kinetic_energy;
* @endcode
*
* @note A common convention in this library is to assign the same name for a type and an object of this type.
* Besides defining them user never works with the types in the source code. All operations
* are done on the objects. Contrarily, the types are the only one visible in the compilation
* errors. Having them of the same names improves user experience and somehow blurs those separate domains.
*
* @tparam Q quantity specification of a parent quantity
* @tparam Args optionally a value of a `quantity_character` in case the base quantity should not be scalar
* or `is_kind` in case the quantity starts a new hierarchy tree of a kind
*/
#ifdef __cpp_explicit_this_parameter
template<detail::NamedQuantitySpec auto QS, detail::IntermediateDerivedQuantitySpec auto Eq,
one_of<quantity_character, struct is_kind> auto... Args>
requires(!requires { QS._equation_; } ||
(requires { QS._equation_; } && (explicitly_convertible(Eq, QS._equation_)))) &&
(... && !QuantitySpec<std::remove_const_t<decltype(Args)>>)
struct quantity_spec<QS, Eq, Args...> : quantity_spec<QS, Args...> {
#else
template<typename Self, detail::NamedQuantitySpec auto QS, detail::IntermediateDerivedQuantitySpec auto Eq,
one_of<quantity_character, struct is_kind> auto... Args>
requires(!requires { QS._equation_; } ||
(requires { QS._equation_; } && (explicitly_convertible(Eq, QS._equation_)))) &&
(... && !QuantitySpec<std::remove_const_t<decltype(Args)>>)
struct quantity_spec<Self, QS, Eq, Args...> : quantity_spec<Self, QS, Args...> {
#endif
static constexpr auto _equation_ = Eq;
static constexpr quantity_character character = detail::quantity_character_init<Args...>(Eq.character);
};
#ifdef __cpp_explicit_this_parameter
#define QUANTITY_SPEC(name, ...) \
inline constexpr struct name : ::mp_units::quantity_spec<##__VA_ARGS__> { \
} name
#else
#define QUANTITY_SPEC(name, ...) \
inline constexpr struct name : ::mp_units::quantity_spec<name, ##__VA_ARGS__> { \
} name
#endif
/**
* @brief A specification of a derived quantity
*
* Derived quantity is a quantity, in a system of quantities, defined in terms of other quantities of that system.
* Its dimension is an expression of the dependence of a quantity on the base quantities of a system of
* quantities as a product of powers of factors corresponding to the base quantities, omitting any numerical factors.
*
* Instead of using a raw list of exponents this library decided to use expression template syntax to make types
* more digestable for the user both for quantity specification and its dimension. The positive exponents are ordered
* first and all negative exponents are put as a list into the `per<...>` class template. If a power of exponent
* is different than `1` the quantity type is enclosed in `power<Q, Num, Den>` class template. Otherwise, it is
* just put directly in the list without any wrapper. In case all of the exponents are negative than the
* `dimensionless`/`dimension_one` is put in the front to increase the readability.
*
* The character of those quantities is derived from ingredients or overriden with a template parameter.
*
* For example:
*
* @code{.cpp}
* auto frequency = 1 / period_duration;
* auto area = pow<2>(length);
* auto speed = distance / duration;
* auto velocity = position_vector / duration;
* auto acceleration = velocity / duration;
* @endcode
*
* - the type of `frequency` is `derived_quantity_spec<dimensionless, per<period_duration>>`
* - the dimension type of `frequency` is `derived_dimension<dimension_one, per<dim_time>>`
* - the type of `area` is `derived_quantity_spec<power<length, 2>>`
* - the dimension type of `area` is `derived_dimension<power<dim_length, 2>>`
* - the type of `speed` is `derived_quantity_spec<distance, per<duration>>`
* - the dimension type of `speed` is `derived_dimension<dim_length, per<dim_time>>`
* - the type of `velocity` is `derived_quantity_spec<position_vector, per<duration>>`
* - the dimension type of `velocity` is `derived_dimension<dim_length, per<dim_time>>`
* - the type of `acceleration` is `derived_quantity_spec<velocity, per<duration>>`
* - the dimension type of `acceleration` is `derived_dimension<dim_length, per<power<dim_time, 2>>>`
*
* @tparam Expr a parameter pack consisting tokens allowed in the quantity specification
* (named quantity specification, `dimensionless`, `power<Q, Num, Den>`, `per<...>`)
*
* @note User should not instantiate this type! It is not exported from the C++ module. The library will
* instantiate this type automatically based on the dimensional arithmetic equation provided by the user.
*/
template<IntermediateDerivedQuantitySpecExpr... Expr>
struct derived_quantity_spec :
detail::quantity_spec_interface<derived_quantity_spec<Expr...>>,
detail::expr_fractions<detail::is_dimensionless, Expr...> {
using _base_ = detail::expr_fractions<detail::is_dimensionless, Expr...>;
static constexpr Dimension auto dimension =
detail::expr_map<detail::to_dimension, derived_dimension, struct dimension_one,
detail::type_list_of_base_dimension_less>(_base_{});
static constexpr quantity_character character =
detail::derived_quantity_character(typename _base_::_num_{}, typename _base_::_den_{});
};
/**
* @brief Quantity of dimension one
*
* Quantity of dimension one also commonly named as "dimensionless" is a quantity with a dimension
* for which all the exponents of the factors corresponding to the base dimensions are zero.
*/
QUANTITY_SPEC(dimensionless, derived_quantity_spec<>{});
/**
* @brief Quantity kind specifier
*
* Specifies that the provided `Q` should be treated as a quantity kind.
*/
template<detail::QuantitySpecWithNoSpecifiers auto Q>
requires(get_kind(Q) == Q)
#ifdef __cpp_explicit_this_parameter
struct kind_of_ : Q {
};
#else
struct kind_of_ : quantity_spec<kind_of_<Q>, Q> {
};
#endif
template<detail::QuantitySpecWithNoSpecifiers auto Q>
requires(get_kind(Q) == Q)
inline constexpr kind_of_<Q> kind_of;
namespace detail {
template<>
struct is_dimensionless<struct dimensionless> : std::true_type {};
template<QuantitySpec auto... From, QuantitySpec Q>
[[nodiscard]] consteval QuantitySpec auto clone_kind_of(Q q)
{
if constexpr ((... && QuantityKindSpec<std::remove_const_t<decltype(From)>>))
return kind_of<Q{}>;
else
return q;
}
} // namespace detail
// Operators
[[nodiscard]] consteval QuantitySpec auto operator*(QuantitySpec auto lhs, QuantitySpec auto rhs)
{
return clone_kind_of<lhs, rhs>(
detail::expr_multiply<derived_quantity_spec, struct dimensionless, detail::type_list_of_quantity_spec_less>(
remove_kind(lhs), remove_kind(rhs)));
}
template<QuantitySpec Lhs, QuantitySpec Rhs>
[[nodiscard]] consteval QuantitySpec auto operator/(Lhs lhs, Rhs rhs)
{
return clone_kind_of<lhs, rhs>(
detail::expr_divide<derived_quantity_spec, struct dimensionless, detail::type_list_of_quantity_spec_less>(
remove_kind(lhs), remove_kind(rhs)));
}
[[nodiscard]] consteval QuantitySpec auto operator/(int value, QuantitySpec auto q)
{
gsl_Expects(value == 1);
return clone_kind_of<q>(detail::expr_invert<derived_quantity_spec, struct dimensionless>(q));
}
[[nodiscard]] consteval QuantitySpec auto operator/(QuantitySpec auto, int) = delete;
template<QuantitySpec Lhs, QuantitySpec Rhs>
[[nodiscard]] consteval bool operator==(Lhs, Rhs)
{
return is_same_v<Lhs, Rhs>;
}
template<QuantityKindSpec Lhs, QuantityKindSpec Rhs>
[[nodiscard]] consteval bool operator==(Lhs, Rhs)
{
return is_same_v<Lhs, Rhs>;
}
template<QuantitySpec Lhs, QuantityKindSpec Rhs>
[[nodiscard]] consteval bool operator==(Lhs, Rhs rhs)
{
return is_same_v<Lhs, std::remove_const_t<decltype(remove_kind(rhs))>>;
}
/**
* @brief Computes the value of a quantity specification raised to the `Num/Den` power
*
* @tparam Num Exponent numerator
* @tparam Den Exponent denominator
* @param q Quantity specification being the base of the operation
*
* @return QuantitySpec The result of computation
*/
template<std::intmax_t Num, std::intmax_t Den = 1, QuantitySpec Q>
requires detail::non_zero<Den>
[[nodiscard]] consteval QuantitySpec auto pow(Q q)
{
if constexpr (q == dimensionless)
return q;
else if constexpr (Num == 1 && Den == 1)
return q;
else if constexpr (detail::IntermediateDerivedQuantitySpec<Q>)
return detail::clone_kind_of<Q{}>(
detail::expr_pow<Num, Den, derived_quantity_spec, struct dimensionless, detail::type_list_of_quantity_spec_less>(
remove_kind(q)));
else if constexpr (Den == 1)
return detail::clone_kind_of<Q{}>(
derived_quantity_spec<power<std::remove_const_t<decltype(remove_kind(Q{}))>, Num>>{});
else
return detail::clone_kind_of<Q{}>(
derived_quantity_spec<power<std::remove_const_t<decltype(remove_kind(Q{}))>, Num, Den>>{});
}
namespace detail {
enum class convertible_result { no, cast, explicit_conversion, yes };
template<QuantitySpec Q>
[[nodiscard]] consteval int get_complexity(Q);
template<typename... Ts>
[[nodiscard]] consteval int get_complexity(type_list<Ts...>)
{
return (0 + ... + get_complexity(Ts{}));
}
template<QuantitySpec Q, int... Ints>
[[nodiscard]] consteval int get_complexity(power<Q, Ints...>)
{
return get_complexity(Q{});
}
template<auto Q>
[[nodiscard]] consteval int get_complexity(kind_of_<Q>)
{
return get_complexity(Q);
}
template<QuantitySpec Q>
[[nodiscard]] consteval int get_complexity(Q)
{
if constexpr (detail::IntermediateDerivedQuantitySpec<Q>)
return get_complexity(typename Q::_num_{}) + get_complexity(typename Q::_den_{});
else if constexpr (requires { Q::_equation_; })
return 1 + get_complexity(Q::_equation_);
else
return 1;
}
template<QuantitySpec Lhs, QuantitySpec Rhs, bool lhs_eq = requires { Lhs::_equation_; },
bool rhs_eq = requires { Rhs::_equation_; }, ratio lhs_compl = get_complexity(Lhs{}),
ratio rhs_compl = get_complexity(Rhs{})>
struct ingredients_less :
std::bool_constant<
(lhs_compl > rhs_compl) ||
(lhs_compl == rhs_compl && (Lhs::dimension != Rhs::dimension && Rhs::dimension == dimension_one) ||
type_name<std::remove_const_t<decltype(Lhs::dimension)>>() <
type_name<std::remove_const_t<decltype(Rhs::dimension)>>()) ||
(lhs_compl == rhs_compl && Lhs::dimension == Rhs::dimension && type_name<Lhs>() < type_name<Rhs>())> {};
template<typename T1, typename T2>
using type_list_of_ingredients_less = expr_less<T1, T2, ingredients_less>;
template<QuantitySpec Q>
requires requires { Q::_equation_; }
[[nodiscard]] consteval bool defines_equation(Q)
{
if constexpr (requires { Q::_parent_._equation_; })
return Q::_parent_._equation_ != Q::_equation_;
else
return true;
}
template<QuantitySpec Q>
struct explode_to_equation_result {
Q equation;
convertible_result result;
};
template<QuantitySpec Q>
requires requires { Q::_equation_; }
[[nodiscard]] consteval auto explode_to_equation(Q q)
{
return explode_to_equation_result{
Q::_equation_, defines_equation(q) ? convertible_result::yes : convertible_result::explicit_conversion};
}
template<QuantitySpec Q, int... Ints>
requires requires { Q::_equation_; }
[[nodiscard]] consteval auto explode_to_equation(power<Q, Ints...>)
{
constexpr ratio exp = power<Q, Ints...>::exponent;
return explode_to_equation_result{pow<exp.num, exp.den>(Q::_equation_), defines_equation(Q{})
? convertible_result::yes
: convertible_result::explicit_conversion};
}
template<QuantitySpec Q>
struct explode_result {
Q quantity;
convertible_result result = convertible_result::yes;
template<typename T>
[[nodiscard]] consteval explode_result common_convertibility_with(explode_to_equation_result<T> res) const
{
return {quantity, std::min(result, res.result)};
}
};
template<int Complexity, IntermediateDerivedQuantitySpec Q>
[[nodiscard]] consteval auto explode(Q q);
template<int Complexity, NamedQuantitySpec Q>
[[nodiscard]] consteval auto explode(Q q);
template<int Complexity, QuantitySpec Q, typename Num, typename... Nums, typename Den, typename... Dens>
[[nodiscard]] consteval auto explode(Q, type_list<Num, Nums...>, type_list<Den, Dens...>)
{
constexpr auto n = get_complexity(Num{});
constexpr auto d = get_complexity(Den{});
constexpr auto max = n > d ? n : d;
if constexpr (max == Complexity || ((n >= d && !requires { explode_to_equation(Num{}); }) ||
(n < d && !requires { explode_to_equation(Den{}); })))
return explode_result{(map_power(Num{}) * ... * map_power(Nums{})) / (map_power(Den{}) * ... * map_power(Dens{}))};
else {
if constexpr (n >= d) {
constexpr auto res = explode_to_equation(Num{});
return explode<Complexity>((res.equation * ... * map_power(Nums{})) /
(map_power(Den{}) * ... * map_power(Dens{})))
.common_convertibility_with(res);
} else {
constexpr auto res = explode_to_equation(Den{});
return explode<Complexity>((map_power(Num{}) * ... * map_power(Nums{})) /
(res.equation * ... * map_power(Dens{})))
.common_convertibility_with(res);
}
}
}
template<int Complexity, QuantitySpec Q, typename Num, typename... Nums>
[[nodiscard]] consteval auto explode(Q, type_list<Num, Nums...>, type_list<>)
{
constexpr auto n = get_complexity(Num{});
if constexpr (n == Complexity || !requires { explode_to_equation(Num{}); })
return explode_result{(map_power(Num{}) * ... * map_power(Nums{}))};
else {
constexpr auto res = explode_to_equation(Num{});
return explode<Complexity>((res.equation * ... * map_power(Nums{}))).common_convertibility_with(res);
}
}
template<int Complexity, QuantitySpec Q, typename Den, typename... Dens>
[[nodiscard]] consteval auto explode(Q, type_list<>, type_list<Den, Dens...>)
{
constexpr auto d = get_complexity(Den{});
if constexpr (d == Complexity || !requires { explode_to_equation(Den{}); })
return explode_result{dimensionless / (map_power(Den{}) * ... * map_power(Dens{}))};
else {
constexpr auto res = explode_to_equation(Den{});
return explode<Complexity>(dimensionless / (res.equation * ... * map_power(Dens{})))
.common_convertibility_with(res);
}
}
template<int Complexity, QuantitySpec Q>
[[nodiscard]] consteval auto explode(Q, type_list<>, type_list<>)
{
return explode_result{dimensionless};
}
template<int Complexity, IntermediateDerivedQuantitySpec Q>
[[nodiscard]] consteval auto explode(Q q)
{
constexpr auto c = get_complexity(q);
if constexpr (c > Complexity)
return explode<Complexity>(q, type_list_sort<typename Q::_num_, type_list_of_ingredients_less>{},
type_list_sort<typename Q::_den_, type_list_of_ingredients_less>{});
else
return explode_result{q};
}
template<int Complexity, NamedQuantitySpec Q>
[[nodiscard]] consteval auto explode(Q q)
{
constexpr auto c = get_complexity(q);
if constexpr (c > Complexity && requires { Q::_equation_; }) {
constexpr auto res = explode_to_equation(q);
return explode<Complexity>(res.equation).common_convertibility_with(res);
} else
return explode_result{q};
}
template<typename NumFrom, typename... NumsFrom, typename DenFrom, typename... DensFrom, typename NumTo,
typename... NumsTo, typename DenTo, typename... DensTo>
[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<NumFrom, NumsFrom...> num_from,
type_list<DenFrom, DensFrom...> den_from,
type_list<NumTo, NumsTo...> num_to,
type_list<DenTo, DensTo...> den_to);
template<typename DenFrom, typename... DensFrom, typename NumTo, typename... NumsTo, typename DenTo, typename... DensTo>
[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<>, type_list<DenFrom, DensFrom...>,
type_list<NumTo, NumsTo...>,
type_list<DenTo, DensTo...>);
template<typename NumFrom, typename... NumsFrom, typename NumTo, typename... NumsTo, typename DenTo, typename... DensTo>
[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<NumFrom, NumsFrom...>, type_list<>,
type_list<NumTo, NumsTo...>,
type_list<DenTo, DensTo...>);
template<typename NumFrom, typename... NumsFrom, typename DenFrom, typename... DensFrom, typename DenTo,
typename... DensTo>
[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<NumFrom, NumsFrom...>,
type_list<DenFrom, DensFrom...>, type_list<>,
type_list<DenTo, DensTo...>);
template<typename NumFrom, typename... NumsFrom, typename DenFrom, typename... DensFrom, typename NumTo,
typename... NumsTo>
[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<NumFrom, NumsFrom...>,
type_list<DenFrom, DensFrom...>,
type_list<NumTo, NumsTo...>, type_list<>);
template<typename NumFrom, typename... NumsFrom, typename NumTo, typename... NumsTo>
[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<NumFrom, NumsFrom...>, type_list<>,
type_list<NumTo, NumsTo...>, type_list<>);
template<typename DenFrom, typename... DensFrom, typename DenTo, typename... DensTo>
[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<>, type_list<DenFrom, DensFrom...>,
type_list<>, type_list<DenTo, DensTo...>);
template<typename... NumsFrom, typename... DensFrom>
[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<NumsFrom...>, type_list<DensFrom...>,
type_list<>, type_list<>);
template<typename... NumsTo, typename... DensTo>
[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<>, type_list<>, type_list<NumsTo...>,
type_list<DensTo...>);
template<typename... NumsFrom>
[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<NumsFrom...>, type_list<>, type_list<>,
type_list<>);
template<typename... DensFrom>
[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<>, type_list<DensFrom...>, type_list<>,
type_list<>);
template<typename... NumsTo>
[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<>, type_list<>, type_list<NumsTo...>,
type_list<>);
template<typename... DensFrom>
[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<>, type_list<>, type_list<>,
type_list<DensFrom...>);
[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<>, type_list<>, type_list<>,
type_list<>);
enum class prepend_rest { no, first, second };
template<QuantitySpec From = struct dimensionless, QuantitySpec To = struct dimensionless, typename Elem = int>
struct extract_results {
bool same_dimension;
From from{};
To to{};
prepend_rest prepend{};
Elem elem{};
};
template<typename From, typename To>
[[nodiscard]] consteval auto extract_convertible_quantities(From from, To to)
{
constexpr auto qfrom = map_power(from);
constexpr auto qto = map_power(to);
if constexpr (qfrom.dimension == qto.dimension) {
if constexpr (is_specialization_of_power<From> && is_specialization_of_power<To>) {
constexpr auto cr = common_ratio(From::exponent, To::exponent);
constexpr auto from_ratio = From::exponent / cr;
constexpr auto to_ratio = To::exponent / cr;
return extract_results{true, pow<from_ratio.num, from_ratio.den>(typename From::factor{}),
pow<to_ratio.num, to_ratio.den>(typename To::factor{}), prepend_rest::no};
} else
return extract_results{true, qfrom, qto, prepend_rest::no};
} else {
auto normalize = []<typename Q>(Q) {
if constexpr (is_specialization_of_power<Q>)
return std::tuple{typename Q::factor{}, Q::exponent};
else
return std::tuple{Q{}, ratio{1}};
};
constexpr auto from_norm = normalize(from);
constexpr auto to_norm = normalize(to);
constexpr auto from_factor = std::get<0>(from_norm);
constexpr auto from_exp = std::get<1>(from_norm);
constexpr auto to_factor = std::get<0>(to_norm);
constexpr auto to_exp = std::get<1>(to_norm);
if constexpr (from_factor.dimension != to_factor.dimension)
return extract_results{false};
else if constexpr (from_exp > to_exp)
return extract_results{true, pow<to_exp.num, to_exp.den>(from_factor), pow<to_exp.num, to_exp.den>(to_factor),
prepend_rest::first,
power_or_T<std::remove_cvref_t<decltype(from_factor)>, from_exp - to_exp>{}};
else
return extract_results{true, pow<from_exp.num, from_exp.den>(from_factor),
pow<from_exp.num, from_exp.den>(to_factor), prepend_rest::second,
power_or_T<std::remove_cvref_t<decltype(to_factor)>, to_exp - from_exp>{}};
}
}
enum class process_entities { numerators, denominators, from, to };
template<process_entities Entities, auto Ext, TypeList NumFrom, TypeList DenFrom, TypeList NumTo, TypeList DenTo>
[[nodiscard]] consteval convertible_result process_extracted(NumFrom num_from, DenFrom den_from, NumTo num_to,
DenTo den_to)
{
if constexpr (Entities == process_entities::numerators || Entities == process_entities::denominators) {
constexpr auto res = convertible_impl(Ext.from, Ext.to);
if constexpr (Ext.prepend == prepend_rest::no)
return std::min(res, are_ingredients_convertible(num_from, den_from, num_to, den_to));
else {
using elem = std::remove_cvref_t<decltype(Ext.elem)>;
if constexpr (Entities == process_entities::numerators) {
if constexpr (Ext.prepend == prepend_rest::first)
return std::min(res,
are_ingredients_convertible(type_list_push_front<NumFrom, elem>{}, den_from, num_to, den_to));
else
return std::min(res,
are_ingredients_convertible(num_from, den_from, type_list_push_front<NumTo, elem>{}, den_to));
} else {
if constexpr (Ext.prepend == prepend_rest::first)
return std::min(res,
are_ingredients_convertible(num_from, type_list_push_front<DenFrom, elem>{}, num_to, den_to));
else
return std::min(res,
are_ingredients_convertible(num_from, den_from, num_to, type_list_push_front<DenTo, elem>{}));
}
}
} else {
if constexpr (Ext.prepend == prepend_rest::no)
return are_ingredients_convertible(num_from, den_from, num_to, den_to);
else {
using elem = std::remove_cvref_t<decltype(Ext.elem)>;
if constexpr (Entities == process_entities::from) {
if constexpr (Ext.prepend == prepend_rest::first)
return are_ingredients_convertible(type_list_push_front<NumFrom, elem>{}, den_from, num_to, den_to);
else
return are_ingredients_convertible(num_from, type_list_push_front<DenFrom, elem>{}, num_to, den_to);
} else {
if constexpr (Ext.prepend == prepend_rest::first)
return are_ingredients_convertible(num_from, den_from, type_list_push_front<NumTo, elem>{}, den_to);
else
return are_ingredients_convertible(num_from, den_from, num_to, type_list_push_front<DenTo, elem>{});
}
}
}
}
template<typename NumFrom, typename... NumsFrom, typename DenFrom, typename... DensFrom, typename NumTo,
typename... NumsTo, typename DenTo, typename... DensTo>
[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<NumFrom, NumsFrom...> num_from,
type_list<DenFrom, DensFrom...> den_from,
type_list<NumTo, NumsTo...> num_to,
type_list<DenTo, DensTo...> den_to)
{
if constexpr (constexpr auto extN = extract_convertible_quantities(NumFrom{}, NumTo{}); extN.same_dimension)
return process_extracted<process_entities::numerators, extN>(type_list<NumsFrom...>{}, den_from,
type_list<NumsTo...>{}, den_to);
else if constexpr (constexpr auto extD = extract_convertible_quantities(DenFrom{}, DenTo{}); extD.same_dimension)
return process_extracted<process_entities::denominators, extD>(num_from, type_list<DensFrom...>{}, num_to,
type_list<DensTo...>{});
else if constexpr (constexpr auto extF = extract_convertible_quantities(NumFrom{}, DenFrom{}); extF.same_dimension)
return process_extracted<process_entities::from, extF>(type_list<NumsFrom...>{}, type_list<DensFrom...>{}, num_to,
den_to);
else if constexpr (constexpr auto extT = extract_convertible_quantities(NumTo{}, DenTo{}); extT.same_dimension)
return process_extracted<process_entities::to, extT>(num_from, den_from, type_list<NumsTo...>{},
type_list<DensTo...>{});
else {
constexpr auto num_from_compl = get_complexity(NumFrom{});
constexpr auto den_from_compl = get_complexity(DenFrom{});
constexpr auto num_to_compl = get_complexity(NumTo{});
constexpr auto den_to_compl = get_complexity(DenTo{});
constexpr auto max = std::max({num_from_compl, num_to_compl, den_from_compl, den_to_compl});
if constexpr (max > 1) {
if constexpr (num_from_compl == max) {
constexpr auto res = explode_to_equation(NumFrom{});
return convertible_impl(
(res.equation * ... * map_power(NumsFrom{})) / (map_power(DenFrom{}) * ... * map_power(DensFrom{})),
(map_power(NumTo{}) * ... * map_power(NumsTo{})) / (map_power(DenTo{}) * ... * map_power(DensTo{})));
} else if constexpr (den_from_compl == max) {
constexpr auto res = explode_to_equation(DenFrom{});
return convertible_impl(
(map_power(NumFrom{}) * ... * map_power(NumsFrom{})) / (res.equation * ... * map_power(DensFrom{})),
(map_power(NumTo{}) * ... * map_power(NumsTo{})) / (map_power(DenTo{}) * ... * map_power(DensTo{})));
} else if constexpr (num_to_compl == max) {
constexpr auto res = explode_to_equation(NumTo{});
return std::min(res.result, convertible_impl((map_power(NumFrom{}) * ... * map_power(NumsFrom{})) /
(map_power(DenFrom{}) * ... * map_power(DensFrom{})),
(res.equation * ... * map_power(NumsTo{})) /
(map_power(DenTo{}) * ... * map_power(DensTo{}))));
} else {
constexpr auto res = explode_to_equation(DenTo{});
return std::min(res.result, convertible_impl((map_power(NumFrom{}) * ... * map_power(NumsFrom{})) /
(map_power(DenFrom{}) * ... * map_power(DensFrom{})),
(map_power(NumTo{}) * ... * map_power(NumsTo{})) /
(res.equation * ... * map_power(DensTo{}))));
}
}
}
return convertible_result::no;
}
template<typename DenFrom, typename... DensFrom, typename NumTo, typename... NumsTo, typename DenTo, typename... DensTo>
[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<> num_from,
type_list<DenFrom, DensFrom...> den_from,
type_list<NumTo, NumsTo...> num_to,
type_list<DenTo, DensTo...>)
{
if constexpr (constexpr auto extD = extract_convertible_quantities(DenFrom{}, DenTo{}); extD.same_dimension)
return process_extracted<process_entities::denominators, extD>(num_from, type_list<DensFrom...>{}, num_to,
type_list<DensTo...>{});
else if constexpr (constexpr auto extT = extract_convertible_quantities(NumTo{}, DenTo{}); extT.same_dimension)
return process_extracted<process_entities::to, extT>(num_from, den_from, type_list<NumsTo...>{},
type_list<DensTo...>{});
else {
constexpr auto den_from_compl = get_complexity(DenFrom{});
constexpr auto num_to_compl = get_complexity(NumTo{});
constexpr auto den_to_compl = get_complexity(DenTo{});
constexpr auto max = std::max({num_to_compl, den_from_compl, den_to_compl});
if constexpr (max > 1) {
if constexpr (den_from_compl == max) {
constexpr auto res = explode_to_equation(DenFrom{});
return convertible_impl(
dimensionless / (res.equation * ... * map_power(DensFrom{})),
(map_power(NumTo{}) * ... * map_power(NumsTo{})) / (map_power(DenTo{}) * ... * map_power(DensTo{})));
} else if constexpr (num_to_compl == max) {
constexpr auto res = explode_to_equation(NumTo{});
return std::min(
res.result, convertible_impl(
dimensionless / (map_power(DenFrom{}) * ... * map_power(DensFrom{})),
(res.equation * ... * map_power(NumsTo{})) / (map_power(DenTo{}) * ... * map_power(DensTo{}))));
} else {
constexpr auto res = explode_to_equation(DenTo{});
return std::min(
res.result, convertible_impl(
dimensionless / (map_power(DenFrom{}) * ... * map_power(DensFrom{})),
(map_power(NumTo{}) * ... * map_power(NumsTo{})) / (res.equation * ... * map_power(DensTo{}))));
}
}
}
return convertible_result::no;
}
template<typename NumFrom, typename... NumsFrom, typename NumTo, typename... NumsTo, typename DenTo, typename... DensTo>
[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<NumFrom, NumsFrom...> num_from,
type_list<> den_from,
type_list<NumTo, NumsTo...>,
type_list<DenTo, DensTo...> den_to)
{
if constexpr (constexpr auto extN = extract_convertible_quantities(NumFrom{}, NumTo{}); extN.same_dimension)
return process_extracted<process_entities::numerators, extN>(type_list<NumsFrom...>{}, den_from,
type_list<NumsTo...>{}, den_to);
else if constexpr (constexpr auto extT = extract_convertible_quantities(NumTo{}, DenTo{}); extT.same_dimension)
return process_extracted<process_entities::to, extT>(num_from, den_from, type_list<NumsTo...>{},
type_list<DensTo...>{});
else {
constexpr auto num_from_compl = get_complexity(NumFrom{});
constexpr auto num_to_compl = get_complexity(NumTo{});
constexpr auto den_to_compl = get_complexity(DenTo{});
constexpr auto max = std::max({num_from_compl, num_to_compl, den_to_compl});
if constexpr (max > 1) {
if constexpr (num_from_compl == max) {
constexpr auto res = explode_to_equation(NumFrom{});
return convertible_impl(
(res.equation * ... * map_power(NumsFrom{})),
(map_power(NumTo{}) * ... * map_power(NumsTo{})) / (map_power(DenTo{}) * ... * map_power(DensTo{})));
} else if constexpr (num_to_compl == max) {
constexpr auto res = explode_to_equation(NumTo{});