Unit Conversion and Dimensional Analysis Library
3.6.1
A compile-time, header-only C++23 dimensional-analysis library
Toggle main menu visibility
Loading...
Searching...
No Matches
time.h
Go to the documentation of this file.
1
//--------------------------------------------------------------------------------------------------
2
//
3
// UnitConversion: A compile-time c++23 unit conversion library with no dependencies
4
//
5
//--------------------------------------------------------------------------------------------------
6
//
7
// The MIT License (MIT)
8
//
9
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
// and associated documentation files (the "Software"), to deal in the Software without
11
// restriction, including without limitation the rights to use, copy, modify, merge, publish,
12
// distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
13
// Software is furnished to do so, subject to the following conditions:
14
//
15
// The above copyright notice and this permission notice shall be included in all copies or
16
// substantial portions of the Software.
17
//
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
19
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
//
24
//--------------------------------------------------------------------------------------------------
25
//
26
// Copyright (c) 2016 Nic Holthaus
27
//
28
//--------------------------------------------------------------------------------------------------
29
//
30
// ATTRIBUTION:
31
// Parts of this work have been adapted from:
32
// http://stackoverflow.com/questions/35069778/create-comparison-trait-for-template-classes-whose-parameters-are-in-a-different
33
// http://stackoverflow.com/questions/28253399/check-traits-for-all-variadic-template-arguments/28253503
34
// http://stackoverflow.com/questions/36321295/rational-approximation-of-square-root-of-stdratio-at-compile-time?noredirect=1#comment60266601_36321295
35
// https://github.com/swatanabe/cppnow17-units
36
//
37
//--------------------------------------------------------------------------------------------------
38
//
41
//
42
//--------------------------------------------------------------------------------------------------
43
44
#pragma once
45
46
#ifndef units_time_h_
47
#define units_time_h_
48
49
#include <
units/core.h
>
50
60
#define UNIT_ADD_WITH_PLURAL_TAG(namespaceName, namePlural, abbreviation,
/*definition*/
...) \
61
UNIT_ADD_STRONG_CONVERSION_FACTOR(namespaceName, namePlural, __VA_ARGS__) \
62
UNIT_ADD_UNIT_DEFINITION(namespaceName, namePlural, __VA_ARGS__) \
63
UNIT_ADD_NAME(namespaceName, namePlural, abbreviation) \
64
UNIT_REGISTER_NAMED_CLASS(namespaceName, namePlural) \
65
UNIT_ADD_LITERALS(namespaceName, namePlural, abbreviation)
66
67
namespace
units
68
{
77
UNIT_ADD_WITH_METRIC_PREFIXES
(
time
, seconds, s,
conversion_factor
<std::ratio<1>, dimension::time>)
78
UNIT_ADD_WITH_PLURAL_TAG
(
time
, minutes, min,
conversion_factor
<
std
::ratio<60>, seconds_>)
79
UNIT_ADD
(
time
, hours, hr,
conversion_factor
<
std
::ratio<60>, minutes<>>)
80
UNIT_ADD
(
time
, days, d,
conversion_factor
<
std
::ratio<24>, hours_>)
81
UNIT_ADD
(
time
, weeks, wk,
conversion_factor
<
std
::ratio<7>, days_>)
82
UNIT_ADD
(
time
, years, yr,
conversion_factor
<
std
::ratio<365>, days_>)
83
UNIT_ADD
(
time
, julian_years, a_j,
conversion_factor
<
std
::ratio<31557600>, seconds_>)
84
UNIT_ADD
(
time
, gregorian_years, a_g,
conversion_factor
<
std
::ratio<31556952>, seconds_>)
85
86
UNIT_ADD
(
time
, fortnights, fn,
conversion_factor
<
std
::ratio<14>, days_>)
87
UNIT_ADD
(
time
, decades, dec,
conversion_factor
<
std
::ratio<10>, julian_years<>>)
88
UNIT_ADD
(
time
, centuries, cent,
conversion_factor
<
std
::ratio<100>, julian_years<>>)
89
UNIT_ADD
(
time
, millennia, kyr,
conversion_factor
<
std
::ratio<1000>, julian_years<>>)
90
91
UNIT_ADD_DIMENSION_TRAIT
(
time
, Time)
92
}
// namespace units
93
94
#endif
// units_time_h_
core.h
unit, dimensional analysis, generic cmath functions, traits (not dimension-specific),...
UNIT_ADD
#define UNIT_ADD(namespaceName, namePlural, abbreviation,...)
Macro for generating the boilerplate code needed for a new unit.
Definition
core.h:447
UNIT_ADD_WITH_METRIC_PREFIXES
#define UNIT_ADD_WITH_METRIC_PREFIXES(namespaceName, namePlural, abbreviation,...)
Macro for generating the boilerplate code needed for a new unit, including its metric prefixes from f...
Definition
core.h:529
UNIT_ADD_DIMENSION_TRAIT
#define UNIT_ADD_DIMENSION_TRAIT(unitdimension, ConceptName)
Macro to create the is_dimension_unit type trait and the ConceptName concept.
Definition
core.h:488
std
STL namespace.
units::time
namespace for unit types and containers representing time values
units
Unit Conversion Library namespace.
Definition
units.h:106
units::conversion_factor
Type representing an arbitrary conversion factor between units.
Definition
core.h:1563
UNIT_ADD_WITH_PLURAL_TAG
#define UNIT_ADD_WITH_PLURAL_TAG(namespaceName, namePlural, abbreviation,...)
Like UNIT_ADD, but WITHOUT the unit constant, whose name would collide with the abbreviation,...
Definition
time.h:60
include
units
time.h
Generated by
1.17.0