forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
units_volume.h
79 lines (60 loc) · 2.14 KB
/
units_volume.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
#pragma once
#ifndef CATA_SRC_UNITS_VOLUME_H
#define CATA_SRC_UNITS_VOLUME_H
#include <algorithm>
#include "units_def.h"
namespace units
{
class volume_in_milliliter_tag
{
};
using volume = quantity<int, volume_in_milliliter_tag>;
const volume volume_min = units::volume( std::numeric_limits<units::volume::value_type>::min(),
units::volume::unit_type{} );
const volume volume_max = units::volume( std::numeric_limits<units::volume::value_type>::max(),
units::volume::unit_type{} );
template<typename value_type>
inline constexpr quantity<value_type, volume_in_milliliter_tag> from_milliliter(
const value_type v )
{
return quantity<value_type, volume_in_milliliter_tag>( v, volume_in_milliliter_tag{} );
}
template<typename value_type>
inline constexpr quantity<value_type, volume_in_milliliter_tag> from_liter( const value_type v )
{
return from_milliliter<value_type>( v * 1000 );
}
template<typename value_type>
inline constexpr value_type to_milliliter( const quantity<value_type, volume_in_milliliter_tag> &v )
{
return v / from_milliliter<value_type>( 1 );
}
inline constexpr double to_liter( const volume &v )
{
return v.value() / 1000.0;
}
// Legacy conversions factor for old volume values.
// Don't use in new code! Use one of the from_* functions instead.
static constexpr volume legacy_volume_factor = from_milliliter( 250 );
} // namespace units
// Implicitly converted to volume, which has int as value_type!
inline constexpr units::volume operator"" _ml( const unsigned long long v )
{
return units::from_milliliter( v );
}
inline constexpr units::quantity<double, units::volume_in_milliliter_tag> operator"" _ml(
const long double v )
{
return units::from_milliliter( v );
}
// Implicitly converted to volume, which has int as value_type!
inline constexpr units::volume operator"" _liter( const unsigned long long v )
{
return units::from_milliliter( v * 1000 );
}
inline constexpr units::quantity<double, units::volume_in_milliliter_tag> operator"" _liter(
const long double v )
{
return units::from_milliliter( v * 1000 );
}
#endif // CATA_SRC_UNITS_VOLUME_H