Unit Conversion and Dimensional Analysis Library 3.6.1
A compile-time, header-only C++23 dimensional-analysis library
Loading...
Searching...
No Matches
data.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_data_h_
47#define units_data_h_
48
49#include <units/core.h>
50
51namespace units
52{
61 // Byte quantities are always at least one, so only the large decimal prefixes (kilo and up) and the
62 // binary prefixes are meaningful; the sub-unit prefixes (deci/centi/milli/... and deca/hecto) are not
63 // spelled out. This also frees the `_dB` literal for the dimensionless decibel, since `decibytes`
64 // would otherwise claim it.
65 UNIT_ADD(data, bytes, B, conversion_factor<std::ratio<1>, dimension::data>)
66 UNIT_ADD(data, kilobytes, kB, kilo<bytes<>>)
67 UNIT_ADD(data, megabytes, MB, mega<bytes<>>)
68 UNIT_ADD(data, gigabytes, GB, giga<bytes<>>)
69 UNIT_ADD(data, terabytes, TB, tera<bytes<>>)
70 UNIT_ADD(data, petabytes, PB, peta<bytes<>>)
71 UNIT_ADD(data, exabytes, EB, conversion_factor<std::ratio<1000>, petabytes_>)
72 UNIT_ADD(data, kibibytes, KiB, kibi<bytes<>>)
73 UNIT_ADD(data, mebibytes, MiB, mebi<bytes<>>)
74 UNIT_ADD(data, gibibytes, GiB, gibi<bytes<>>)
75 UNIT_ADD(data, tebibytes, TiB, tebi<bytes<>>)
76 UNIT_ADD(data, pebibytes, PiB, pebi<bytes<>>)
77 UNIT_ADD(data, exbibytes, EiB, exbi<bytes<>>)
78
79 UNIT_ADD(data, bits, b, conversion_factor<std::ratio<1, 8>, bytes_>)
80 UNIT_ADD(data, kilobits, kb, kilo<bits<>>)
81 UNIT_ADD(data, megabits, Mb, mega<bits<>>)
82 UNIT_ADD(data, gigabits, Gb, giga<bits<>>)
83 UNIT_ADD(data, terabits, Tb, tera<bits<>>)
84 UNIT_ADD(data, petabits, Pb, peta<bits<>>)
85 UNIT_ADD(data, exabits, Eb, conversion_factor<std::ratio<1000>, petabits_>)
86 UNIT_ADD(data, kibibits, Kib, kibi<bits<>>)
87 UNIT_ADD(data, mebibits, Mib, mebi<bits<>>)
88 UNIT_ADD(data, gibibits, Gib, gibi<bits<>>)
89 UNIT_ADD(data, tebibits, Tib, tebi<bits<>>)
90 UNIT_ADD(data, pebibits, Pib, pebi<bits<>>)
91 UNIT_ADD(data, exbibits, Eib, exbi<bits<>>)
92
93 UNIT_ADD(data, nibbles, nibble, conversion_factor<std::ratio<4>, bits_>)
94
96} // namespace units
97
98#endif // units_data_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_DIMENSION_TRAIT(unitdimension, ConceptName)
Macro to create the is_dimension_unit type trait and the ConceptName concept.
Definition core.h:488
typename detail::prefix< std::ratio< 1152921504606846976 >, Cf >::type exbi
< Represents the type of class Cf with the binary 'pebi' prefix appended.
Definition core.h:2020
typename detail::prefix< std::ratio< 1125899906842624 >, Cf >::type pebi
< Represents the type of class Cf with the binary 'tebi' prefix appended.
Definition core.h:2019
typename detail::prefix< std::ratio< 1073741824 >, Cf >::type gibi
< Represents the type of class Cf with the binary 'mibi' prefix appended.
Definition core.h:2017
typename detail::prefix< std::ratio< 1048576 >, Cf >::type mebi
< Represents the type of class Cf with the binary 'kibi' prefix appended.
Definition core.h:2016
typename detail::prefix< std::ratio< 1099511627776 >, Cf >::type tebi
< Represents the type of class Cf with the binary 'gibi' prefix appended.
Definition core.h:2018
typename detail::prefix< std::ratio< 1024 >, Cf >::type kibi
< Represents the type of class Cf with the metric 'exa' prefix appended.
Definition core.h:2015
typename detail::prefix< std::giga, Cf >::type giga
< Represents the type of class Cf with the metric 'mega' prefix appended.
Definition core.h:2005
typename detail::prefix< std::mega, Cf >::type mega
< Represents the type of class Cf with the metric 'kilo' prefix appended.
Definition core.h:2004
typename detail::prefix< std::kilo, Cf >::type kilo
< Represents the type of class Cf with the metric 'hecto' prefix appended.
Definition core.h:2003
typename detail::prefix< std::peta, Cf >::type peta
< Represents the type of class Cf with the metric 'tera' prefix appended.
Definition core.h:2007
typename detail::prefix< std::tera, Cf >::type tera
< Represents the type of class Cf with the metric 'giga' prefix appended.
Definition core.h:2006
STL namespace.
namespace for unit types and containers representing data values
make_dimension< data_tag > data
< Represents a unit of concentration
Definition core.h:1379
Unit Conversion Library namespace.
Definition units.h:106
Type representing an arbitrary conversion factor between units.
Definition core.h:1563