Unit Conversion and Dimensional Analysis Library 3.6.1
A compile-time, header-only C++23 dimensional-analysis library
Loading...
Searching...
No Matches
volume.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_volume_h_
47#define units_volume_h_
48
49#include <units/length.h>
50
51namespace units
52{
61 UNIT_ADD(volume, cubic_meters, m3, conversion_factor<std::ratio<1>, dimension::volume>)
62 UNIT_ADD(volume, cubic_millimeters, mm3, cubed<millimeters_>)
63 UNIT_ADD(volume, cubic_kilometers, km3, cubed<kilometers<>>)
64 UNIT_ADD_WITH_METRIC_PREFIXES(volume, liters, L, cubed<decimeters<>>)
65 UNIT_ADD(volume, cubic_inches, in3, cubed<inches<>>)
66 UNIT_ADD(volume, cubic_feet, ft3, cubed<feet<>>)
67 UNIT_ADD(volume, cubic_yards, yd3, cubed<yards<>>)
68 UNIT_ADD(volume, cubic_miles, mi3, cubed<miles<>>)
69 UNIT_ADD(volume, gallons, gal, conversion_factor<std::ratio<231>, cubic_inches<>>)
70 UNIT_ADD(volume, quarts, qt, conversion_factor<std::ratio<1, 4>, gallons<>>)
71 UNIT_ADD(volume, pints, pt, conversion_factor<std::ratio<1, 2>, quarts<>>)
72 UNIT_ADD(volume, cups, c, conversion_factor<std::ratio<1, 2>, pints<>>)
73 UNIT_ADD(volume, fluid_ounces, fl_oz, conversion_factor<std::ratio<1, 8>, cups<>>)
74 UNIT_ADD(volume, barrels, bl, conversion_factor<std::ratio<42>, gallons<>>)
75 UNIT_ADD(volume, bushels, bu, conversion_factor<std::ratio<215042, 100>, cubic_inches<>>)
76 UNIT_ADD(volume, cords, cord, conversion_factor<std::ratio<128>, cubic_feet<>>)
77 UNIT_ADD(volume, cubic_fathoms, fm3, cubed<fathoms<>>)
78 UNIT_ADD(volume, tablespoons, tbsp, conversion_factor<std::ratio<1, 2>, fluid_ounces<>>)
79 UNIT_ADD(volume, teaspoons, tsp, conversion_factor<std::ratio<1, 6>, fluid_ounces<>>)
80 UNIT_ADD(volume, pinches, pinch, conversion_factor<std::ratio<1, 8>, teaspoons<>>)
81 UNIT_ADD(volume, dashes, dash, conversion_factor<std::ratio<1, 2>, pinches<>>)
82 UNIT_ADD(volume, drops, drop, conversion_factor<std::ratio<1, 360>, fluid_ounces<>>)
83 UNIT_ADD(volume, fifths, fifth, conversion_factor<std::ratio<1, 5>, gallons<>>)
84 UNIT_ADD(volume, drams, dr, conversion_factor<std::ratio<1, 8>, fluid_ounces<>>)
85 UNIT_ADD(volume, gills, gi, conversion_factor<std::ratio<4>, fluid_ounces<>>)
86 UNIT_ADD(volume, pecks, pk, conversion_factor<std::ratio<1, 4>, bushels<>>)
87 UNIT_ADD(volume, sacks, sck, conversion_factor<std::ratio<3>, bushels<>>)
88 UNIT_ADD(volume, shots, shts, conversion_factor<std::ratio<3, 2>, fluid_ounces<>>)
89 UNIT_ADD(volume, strikes, strk, conversion_factor<std::ratio<2>, bushels<>>)
90
92} // namespace units
93
94#endif // units_volume_h_
#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
typename detail::cubed_impl< Cf >::type cubed
represents the type of class U cubed.
Definition core.h:1695
units representing length values
STL namespace.
constexpr meters_per_second c(299792458.0)
Speed of light in vacuum.
dimension_pow< length, std::ratio< 3 > > volume
< Represents an SI derived unit of area
Definition core.h:1344
namespace for unit types and containers representing volume values
Unit Conversion Library namespace.
Definition units.h:106
Type representing an arbitrary conversion factor between units.
Definition core.h:1563