-
Notifications
You must be signed in to change notification settings - Fork 5
/
mpusz_units.hpp
68 lines (52 loc) · 2.28 KB
/
mpusz_units.hpp
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
#ifndef QUAN_COMPATIBILITY_MPUSZ_UNITS_HPP_INCLUDED
#define QUAN_COMPATIBILITY_MPUSZ_UNITS_HPP_INCLUDED
#include <units/quantity.h>
#include <quan/meta/binary_op.hpp>
#include <quan/meta/is_scalar.hpp>
namespace quan{ namespace meta{ namespace impl{
/*
quan has a different view on what a scalar is to mpusz::units.
No matter, though confusing, they can work together
*/
template <units::Quantity Q>
struct is_scalar_impl<Q> : std::true_type{};
// quan (has been around since 2003) uses specialisations of binary_op_impl
// for result type deduction on operations. Back then there was no such thing as decltype and auto etc.
// Though you can use decltype for deduction, there may be some types
// that dont have any runtime operations so this type may still be useful
// though maybe one could define the runtime operators on the meta types anyway
// anyway here is the basic integration to get units::Quantity working with quan::two_d::vector
template <units::Quantity Lhs, units::Quantity Rhs>
struct binary_op_impl<Lhs, quan::meta::plus, Rhs>{
typedef decltype(Lhs{} + Rhs{}) type;
};
template <units::Quantity Lhs, units::Quantity Rhs>
struct binary_op_impl<Lhs, quan::meta::minus, Rhs>{
typedef decltype(Lhs{} - Rhs{}) type;
};
template <units::Quantity Lhs, units::Quantity Rhs>
struct binary_op_impl<Lhs, quan::meta::times, Rhs>{
typedef decltype(Lhs{} * Rhs{}) type;
};
template <units::Quantity Lhs, units::Scalar Rhs>
struct binary_op_impl<Lhs, quan::meta::times, Rhs>{
typedef decltype(Lhs{} * Rhs{}) type;
};
template <units::Scalar Lhs, units::Quantity Rhs>
struct binary_op_impl<Lhs, quan::meta::times, Rhs>{
typedef decltype(Lhs{} * Rhs{}) type;
};
template <units::Quantity Lhs, units::Quantity Rhs>
struct binary_op_impl<Lhs, quan::meta::divides, Rhs>{
typedef decltype(Lhs{} / Rhs{}) type;
};
template <units::Quantity Lhs, units::Scalar Rhs>
struct binary_op_impl<Lhs, quan::meta::divides, Rhs>{
typedef decltype(Lhs{} / Rhs{}) type;
};
template <units::Scalar Lhs, units::Quantity Rhs>
struct binary_op_impl<Lhs, quan::meta::divides, Rhs>{
typedef decltype(Lhs{} / Rhs{}) type;
};
}}}
#endif // QUAN_COMPATIBILITY_MPUSZ_UNITS_HPP_INCLUDED