Unit Conversion and Dimensional Analysis Library 3.6.1
A compile-time, header-only C++23 dimensional-analysis library
Loading...
Searching...
No Matches
length.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_length_h_
47#define units_length_h_
48
49#include <units/core.h>
50
51namespace units
52{
61 UNIT_ADD_WITH_METRIC_PREFIXES(length, meters, m, conversion_factor<std::ratio<1>, dimension::length>)
62 UNIT_ADD(length, feet, ft, conversion_factor<std::ratio<381, 1250>, meters<>>)
63 UNIT_ADD(length, inches, in, conversion_factor<std::ratio<1, 12>, feet<>>)
64 UNIT_ADD(length, mils, mil, conversion_factor<std::ratio<1, 1000>, inches<>>)
65 UNIT_ADD(length, miles, mi, conversion_factor<std::ratio<5280>, feet<>>)
66 UNIT_ADD(length, nautical_miles, nmi, conversion_factor<std::ratio<1852>, meters<>>)
67 UNIT_ADD(length, astronomical_units, au, conversion_factor<std::ratio<149597870700>, meters<>>)
68 UNIT_ADD(length, lightyears, ly, conversion_factor<std::ratio<9460730472580800>, meters<>>)
69 UNIT_ADD(length, parsecs, pc, conversion_factor<std::ratio<648000>, astronomical_units<>, std::ratio<-1>>)
70 UNIT_ADD(length, angstroms, angstrom, conversion_factor<std::ratio<1, 10>, nanometers<>>)
71 UNIT_ADD(length, cubits, cbt, conversion_factor<std::ratio<18>, inches<>>)
72 UNIT_ADD(length, fathoms, ftm, conversion_factor<std::ratio<6>, feet<>>)
73 UNIT_ADD(length, chains, ch, conversion_factor<std::ratio<66>, feet<>>)
74 UNIT_ADD(length, furlongs, fur, conversion_factor<std::ratio<10>, chains<>>)
75 UNIT_ADD(length, hands, hand, conversion_factor<std::ratio<4>, inches<>>)
76 UNIT_ADD(length, leagues, lea, conversion_factor<std::ratio<3>, miles<>>)
77 UNIT_ADD(length, nautical_leagues, nl, conversion_factor<std::ratio<3>, nautical_miles<>>)
78 UNIT_ADD(length, yards, yd, conversion_factor<std::ratio<3>, feet<>>)
79
80 // british spelling aliases
81 template<class Underlying>
82 using metres = meters<Underlying>;
83
84 UNIT_ADD(length, rods, rod, conversion_factor<std::ratio<1, 4>, chains<>>)
85 UNIT_ADD(length, links, li, conversion_factor<std::ratio<1, 100>, chains<>>)
86 UNIT_ADD(length, barleycorns, bc, conversion_factor<std::ratio<1, 3>, inches<>>)
87 UNIT_ADD(length, nails, nail, conversion_factor<std::ratio<1, 16>, yards<>>)
88 UNIT_ADD(length, spans, span, conversion_factor<std::ratio<9>, inches<>>)
89 UNIT_ADD(length, picas, pica, conversion_factor<std::ratio<1, 6>, inches<>>)
90 UNIT_ADD(length, points, pnt, conversion_factor<std::ratio<1, 72>, inches<>>)
91
93} // namespace units
94
95#endif // units_length_h_
unit, dimensional analysis, generic cmath functions, traits (not dimension-specific),...
#define UNIT_ADD(namespaceName, namePlural, abbreviation,...)
Macro for generating the boilerplate code needed for a new unit.
Definition core.h:447
#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
#define UNIT_ADD_DIMENSION_TRAIT(unitdimension, ConceptName)
Macro to create the is_dimension_unit type trait and the ConceptName concept.
Definition core.h:488
STL namespace.
namespace for unit types and containers representing length values
Unit Conversion Library namespace.
Definition units.h:106
Type representing an arbitrary conversion factor between units.
Definition core.h:1563