Last active
January 21, 2022 23:14
-
-
Save VulpineAmethyst/db58b8cd5732ecf28e74f2f6feb692ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| #include "mesitypes.h" | |
| /* | |
| * US customary units, in all their messy glory, hence 'messytypes.h'. | |
| * | |
| * Code by Síle Ekaterin Liszka, aka Sheila/VulpineAmethyst. | |
| */ | |
| namespace Messy { | |
| namespace US { | |
| // Length | |
| // International US customary units (yes, I know). | |
| using Feet = Mesi::Meters::Multiply<3048>::Divide<10000>; | |
| using Inches = Feet::Divide<12>; | |
| using Picas = Inches::Divide<6>; | |
| using Points = Picas::Divide<12>; | |
| using Yards = Feet::Multiply<3>; | |
| using Miles = Feet::Multiply<5280>; | |
| // International nautical units. | |
| using Fathoms = Mesi::Meters::Multiply<1143>::Divide<625>; | |
| using Cables = Fathoms::Multiply<120>; | |
| using NauticalMiles = Mesi::Meters::Multiply<1852>; | |
| using InchesSq = decltype(Inches{} * Inches{}); | |
| namespace Survey { | |
| // US Survey units. | |
| using Links = Inches::Multiply<33>::Divide<50>; | |
| using Feet = Mesi::Meters::Multiply<1200>::Divide<3937>; | |
| using Rods = Links::Multiply<25>; | |
| using Chains = Rods::Multiply<4>; | |
| using Furlongs = Chains::Multiply<10>; | |
| using Miles = Furlongs::Multiply<8>; | |
| using Leagues = Miles::Multiply<3>; | |
| // Area | |
| using ChainsSq = decltype(Chains{} * Chains{}); | |
| using FeetSq = InchesSq::Multiply<144>; | |
| using Acres = FeetSq::Multiply<43560>; | |
| using Sections = Acres::Multiply<640>; | |
| using Townships = Sections::Multiply<36>; | |
| } | |
| // Volume | |
| // General volume. | |
| using InchesCu = decltype(Inches{} * InchesSq{}); | |
| using FeetCu = decltype(Feet{} * Feet{} * Feet{}); | |
| using YardsCu = FeetCu::Multiply<27>; | |
| using AcreFeet = FeetCu::Multiply<43560>; | |
| // Liquid volume. | |
| using Gallons = InchesCu::Multiply<231>; | |
| using Hogsheads = Gallons::Multiply<63>; | |
| using Barrels = Hogsheads::Divide<2>; | |
| using OilBarrels = Gallons::Multiply<42>; | |
| using FluidOunces = Gallons::Divide<128>; | |
| using Cups = FluidOunces::Multiply<8>; | |
| using Tablespoons = FluidOunces::Divide<2>; | |
| using Teaspoons = Tablespoons::Divide<3>; | |
| using FluidDrams = Tablespoons::Divide<4>; | |
| using Minims = FluidDrams::Divide<60>; | |
| using Shots = Tablespoons::Multiply<3>; | |
| using Gills = FluidOunces::Multiply<4>; | |
| namespace Dry { | |
| // Dry volume. | |
| using Barrels = InchesCu::Multiply<7056>; | |
| using Bushels = Barrels::Multiply<1000>::Divide<3281>; | |
| using Pecks = Bushels::Divide<4>; | |
| using Gallons = Pecks::Divide<2>; | |
| using Quarts = Gallons::Divide<4>; | |
| using Pints = Quarts::Divide<2>; | |
| } | |
| // Mass | |
| // Avoirdupois. | |
| using Grains = Mesi::Grams::Multiply<6479891>::Divide<100000>; | |
| using Drams = Grains::Multiply<27 * 32 + 11>::Divide<32>; | |
| using Ounces = Drams::Multiply<16>; | |
| using Pounds = Ounces::Multiply<16>; | |
| using Hundredweights = Pounds::Multiply<100>; | |
| using LongHundredweights = Pounds::Multiply<112>; | |
| using Tons = Hundredweights::Multiply<20>; | |
| using LongTons = LongHundredweights::Multiply<20>; | |
| namespace Troy { | |
| // Troy | |
| using Grains = Pounds::Divide<7000>; | |
| using Pennyweights = Grains::Multiply<24>; | |
| using Ounces = Pennyweights::Multiply<20>; | |
| using Pounds = Ounces::Multiply<12>; | |
| } | |
| // Reference units. | |
| using Liters = Mesi::MetersCu::Multiply<1>::Divide<1000>; | |
| using Milliliters = Mesi::Milli<Liters>; | |
| namespace Cooking { | |
| // Cooking volume. | |
| using Teaspoons = Milliliter::Multiply<493>::Divide<100>; | |
| using Tablespoons = Milliliter::Multiply<1479>::Divide<100>; | |
| using FluidOounces = Milliliter::Multiply<2957>::Divide<100>; | |
| using Cups = Milliliter::Multiply<23659>::Divide<100>; | |
| using Pints = Milliliter::Multiply<56826>::Divide<100>; | |
| namespace FDA { | |
| using Teaspoons = Milliliter::Multiply<5>; | |
| using Tablespoons = Milliliter::Multiply<15>; | |
| using FluidOunces = Milliliter::Multiply<30>; | |
| using Cups = Milliliter::Multiply<240>; | |
| } | |
| } | |
| namespace Literals { | |
| #define LITERAL_TYPE(T, SUFFIX) \ | |
| constexpr auto operator "" SUFFIX(long double arg) { return T(arg); } \ | |
| constexpr auto operator "" SUFFIX(unsigned long long arg) { return T(arg); } | |
| LITERAL_TYPE(Feet, _ft) | |
| LITERAL_TYPE(Inches, _in) | |
| LITERAL_TYPE(Picas, _pc) | |
| LITERAL_TYPE(Yards, _yd) | |
| LITERAL_TYPE(Miles, _mi) | |
| LITERAL_TYPE(Fathoms, _ftm) | |
| LITERAL_TYPE(Cables, _cb) | |
| LITERAL_TYPE(NauticalMiles, _nmi) | |
| LITERAL_TYPE(Survey::Links, _li) | |
| LITERAL_TYPE(Survey::Chains, _ch) | |
| LITERAL_TYPE(Survey::Furlongs, _fur) | |
| LITERAL_TYPE(Survey::Miles, _smi) | |
| LITERAL_TYPE(Survey::Leagues, _lea) | |
| LITERAL_TYPE(Survey::FeetSq, _ft2) | |
| LITERAL_TYPE(Survey::ChainsSq, _ch2) | |
| LITERAL_TYPE(Survey::Townships, _twp) | |
| LITERAL_TYPE(InchesCu, _in3) | |
| LITERAL_TYPE(FeetCu, _ft3) | |
| LITERAL_TYPE(YardsCu, _yd3) | |
| LITERAL_TYPE(AcreFeet, _acreft) | |
| LITERAL_TYPE(Minims, _min) | |
| LITERAL_TYPE(FluidDrams, _fldr) | |
| LITERAL_TYPE(Teaspoons, _tsp) | |
| LITERAL_TYPE(Tablespoons, _tbsp) | |
| LITERAL_TYPE(FluidOunces, _floz) | |
| LITERAL_TYPE(Shots, _jig) | |
| LITERAL_TYPE(Gills, _gi) | |
| LITERAL_TYPE(Cups, _c) | |
| LITERAL_TYPE(Pints, _pt) | |
| LITERAL_TYPE(Quarts, _qt) | |
| LITERAL_TYPE(Gallons, _gal) | |
| LITERAL_TYPE(Barrels, _bbl) | |
| LITERAL_TYPE(Dry::Pecks, _pk) | |
| LITERAL_TYPE(Dry::Bushels, _bu) | |
| LITERAL_TYPE(Grains, _gr) | |
| LITERAL_TYPE(Drams, _dr) | |
| LITERAL_TYPE(Ounces, _oz) | |
| LITERAL_TYPE(Pounds, _lb) | |
| LITERAL_TYPE(Hundredweights, _cwt) | |
| LITERAL_TYPE(Troy::Pennyweights, _dwt) | |
| LITERAL_TYPE(Troy::Ounces, _ozt) | |
| LITERAL_TYPE(Troy::Pounds, _lbt) | |
| #undef LITERAL_TYPE | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment