OGLplus  (0.59.0) a C++ wrapper for rendering APIs

unit.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_UNITS_UNIT_HPP
10 #define EAGINE_UNITS_UNIT_HPP
11 
12 #include "default.hpp"
13 #include "detail.hpp"
14 #include "traits.hpp"
15 
16 namespace eagine::units {
17 
18 // unit
19 template <typename Dims, typename System>
20 struct unit {
21  using dimension = Dims;
22  using system = System;
23  using scale = scales::one;
24  using type = unit;
25 };
26 
27 template <typename X>
28 auto get_dimension(X) noexcept {
29  return dimension_of_t<X>{};
30 }
31 
32 // value conv
33 template <typename D, typename S>
34 struct value_conv<unit<D, S>, unit<D, S>> : trivial_value_conv {};
35 
36 // add_result
37 template <typename D, typename S>
38 struct add_result<unit<D, S>, unit<D, S>> : unit<D, S> {};
39 
40 // sub_result
41 template <typename D, typename S>
42 struct sub_result<unit<D, S>, unit<D, S>> : unit<D, S> {};
43 
44 // mul_l_operand
45 template <typename D1, typename D2, typename S>
46 struct mul_l_operand<unit<D1, S>, unit<D2, S>> : unit<D1, S> {};
47 
48 // mul_r_operand
49 template <typename D1, typename D2, typename S>
50 struct mul_r_operand<unit<D1, S>, unit<D2, S>> : unit<D2, S> {};
51 
52 // mul_result
53 template <typename D1, typename D2, typename S>
54 struct mul_result<unit<D1, S>, unit<D2, S>>
55  : unit<bits::dim_add_t<D1, D2>, S> {};
56 
57 // div_result
58 template <typename D1, typename D2, typename S>
59 struct div_result<unit<D1, S>, unit<D2, S>>
60  : unit<bits::dim_sub_t<D1, D2>, S> {};
61 
62 // quotation
63 template <typename U>
64 static constexpr auto operator!(U) noexcept
65  -> std::enable_if_t<is_unit_v<U>, lit_result_t<U>> {
66  return {};
67 }
68 
69 // addition
70 template <typename U1, typename U2>
71 static constexpr auto operator+(U1, U2) noexcept
72  -> std::enable_if_t<is_unit_v<U1> && is_unit_v<U2>, add_result_t<U1, U2>> {
73  return {};
74 }
75 
76 // subtraction
77 template <typename U1, typename U2>
78 static constexpr auto operator-(U1, U2) noexcept
79  -> std::enable_if_t<is_unit_v<U1> && is_unit_v<U2>, sub_result_t<U1, U2>> {
80  return {};
81 }
82 
83 // multiplication
84 template <typename U1, typename U2>
85 static constexpr auto operator*(U1, U2) noexcept
86  -> std::enable_if_t<is_unit_v<U1> && is_unit_v<U2>, mul_result_t<U1, U2>> {
87  return {};
88 }
89 
90 // division
91 template <typename U1, typename U2>
92 static constexpr auto operator/(U1, U2) noexcept
93  -> std::enable_if_t<is_unit_v<U1> && is_unit_v<U2>, div_result_t<U1, U2>> {
94  return {};
95 }
96 
97 } // namespace eagine::units
98 
99 #endif // EAGINE_UNITS_UNIT_HPP
static auto scale(std::shared_ptr< generator > gen, std::array< float, 3 > s) noexcept
Constructs instances of scaled_gen modifier.
Definition: scaled.hpp:41
static auto operator+(const fixed_size_string< N1 > &s1, const fixed_size_string< N2 > &s2) noexcept
Concatenation operator for fixed_size_string.
Definition: fixed_size_str.hpp:135

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).