MT Core (C++)
Core library for replacing C++ standard in project usage
Loading...
Searching...
No Matches
base.hpp File Reference
#include "mtcore/math/core.hpp"
#include "mtcore/math/templates.hpp"
#include "mtcore/meta/base.hpp"
#include <numbers>
#include <ratio>
Include dependency graph for units/base.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  mtcore::units::Unit< UnitCategory, S, PiPow, Tr, exp >
 Represents a single unit of measurement. More...
 
struct  mtcore::units::Units< Unit< Id, S, PiPow, Tr, Exp >, Mappings... >
 
struct  mtcore::units::Units<>
 
struct  mtcore::units::UnitValue< Underlying, Units<> >
 Specialization where units list is empty (basically a "unitless" value) Can be directly cast to a numeric type. More...
 
struct  mtcore::units::UnitValue< Underlying, Units< U1, UnitsSub... > >
 Represents a unit value with a specific, non-empty unit list. More...
 

Namespaces

namespace  mtcore
 Core library for C++ with Zig-related functionality.
 
namespace  mtcore::units
 Base namespace for units.
 
namespace  mtcore::units::dimensions
 Represents prebuilt dimensions for units.
 

Concepts

concept  mtcore::units::IsUnit
 Concept to check that a type is a unit.
 
concept  mtcore::units::IsUnitValue
 Concept to check something is a unit value.
 

Macros

#define MTCORE_DEF_UNIT_NAME_NO_ABBREV(NS, UNIT)
 
#define MTCORE_DEF_UNIT_NAME_SYM(NS, UNIT, ABBREV, SYM)
 
#define MTCORE_DEF_UNIT_NAME_STRS(NS, UNIT, NAME, US_NAME, ABBREV, ABBREV_ASCII, ABBREV_US, SYMBOL)
 
#define MTCORE_DEF_UNIT_NAME(NS, UNIT, ABBREV)
 
#define MTCORE_DEF_UNIT_NAME_DIFF_US(NS, UNIT, US_NAME, ABBREV)
 
#define MTCORE_DEF_UNIT_NAME_UNIC_ABB(NS, UNIT, US_NAME, ABBREV, UNIC_ABB)
 
#define MTCORE_DEF_UNIT_NAME_SI_PREFIXES_SMALL(NS, UNIT, US_NAME, ABBREV)
 
#define MTCORE_DEF_UNIT_NAME_SI_PREFIXES_LARGE(NS, UNIT, US_NAME, ABBREV)
 
#define MTCORE_DEF_UNIT_NAME_SI(NS, UNIT, US_NAME, ABBREV)
 

Functions

template<std::floating_point Val, typename... Dims>
constexpr UnitValue< Val, Units< Dims... > > mtcore::units::operator* (Val lhs, const Units< Dims... > &)
 Multiply a number with units to get a unit value.
 
template<typename... Dims1, typename... Dims2>
constexpr auto mtcore::units::operator* (const Units< Dims1... > &, const Units< Dims2... > &)
 Multiply units to combine them.
 
template<typename... Dims1, typename... Dims2>
constexpr auto mtcore::units::operator/ (const Units< Dims1... > &, const Units< Dims2... > &)
 Divide units to combine them.
 
template<std::floating_point Val, typename... Dims>
constexpr auto mtcore::units::operator/ (Val lhs, const Units< Dims... > &)
 Divide units with a number to get a unit value.
 
template<typename U1, typename Us1, typename U2, typename Us2>
constexpr auto mtcore::units::operator* (const UnitValue< U1, Us1 > &lhs, const UnitValue< U2, Us2 > &rhs)
 Multiply unit values together.
 
template<typename U1, typename Us1, typename U2, typename Us2>
constexpr auto mtcore::units::operator/ (const UnitValue< U1, Us1 > &lhs, const UnitValue< U2, Us2 > &rhs)
 Divide unit values.
 
template<std::floating_point I, typename U, typename Us>
constexpr auto mtcore::units::operator/ (I value, UnitValue< U, Us > lhs)
 Divide a number with a unit value.
 
template<std::floating_point I, typename U, typename Us>
constexpr auto mtcore::units::operator/ (UnitValue< U, Us > lhs, I value)
 Divide a unit value with a number.
 
template<std::integral I, typename U, typename Us>
constexpr auto mtcore::units::operator/ (I value, const UnitValue< U, Us > &lhs)
 Divide a number with a unit value.
 
template<std::floating_point Val, typename U, typename Us>
constexpr UnitValue< U, Us > mtcore::units::operator* (const UnitValue< U, Us > &lhs, Val rhs)
 Multiply a unit value with a number.
 
template<std::floating_point Val, typename U, typename Us>
constexpr UnitValue< Val, Us > mtcore::units::operator* (Val lhs, const UnitValue< U, Us > &rhs)
 Multiply a unit value with a number.
 
template<typename U, typename Us, typename... Dims>
constexpr auto mtcore::units::operator* (UnitValue< U, Us > lhs, const Units< Dims... > &u)
 Multiply a unit value with units to combine them.
 
template<typename U, typename Us, typename... Dims>
constexpr auto mtcore::units::operator/ (UnitValue< U, Us > lhs, const Units< Dims... > &u)
 Divide a unit value with units to combine them.
 

Variables

constexpr size_t mtcore::units::dimensions::LENGTH = 0
 For units representing length.
 
constexpr size_t mtcore::units::dimensions::MASS = 1
 For units representing mass.
 
constexpr size_t mtcore::units::dimensions::TIME = 2
 For units representing time.
 
constexpr size_t mtcore::units::dimensions::ANGLE = 3
 For units representing angles.
 
constexpr size_t mtcore::units::dimensions::CURRENT = 4
 For units representing current (electricity)
 
constexpr size_t mtcore::units::dimensions::TEMPERATURE = 5
 For units representing temperature.
 
constexpr size_t mtcore::units::dimensions::SUBSTANCE = 6
 For units representing substance.
 
constexpr size_t mtcore::units::dimensions::LUMINOSITY = 7
 For units representing luminosity.
 
constexpr size_t mtcore::units::dimensions::STORAGE = 8
 For units representing storage.
 

Macro Definition Documentation

◆ MTCORE_DEF_UNIT_NAME

#define MTCORE_DEF_UNIT_NAME ( NS,
UNIT,
ABBREV )
Value:
template<> \
struct UnitName<std::remove_cvref_t<decltype(NS::UNIT)>> { \
static constexpr std::string_view nameUs = #UNIT; \
static constexpr std::string_view name = #UNIT; \
static constexpr std::string_view abbrev = #ABBREV; \
static constexpr std::string_view abbrevUs = #ABBREV; \
static constexpr std::string_view abbrevAscii = #ABBREV; \
static constexpr std::string_view symbol = ""; \
};

Definition at line 915 of file units/base.hpp.

915#define MTCORE_DEF_UNIT_NAME(NS, UNIT, ABBREV) \
916 template<> \
917 struct UnitName<std::remove_cvref_t<decltype(NS::UNIT)>> { \
918 static constexpr std::string_view nameUs = #UNIT; \
919 static constexpr std::string_view name = #UNIT; \
920 static constexpr std::string_view abbrev = #ABBREV; \
921 static constexpr std::string_view abbrevUs = #ABBREV; \
922 static constexpr std::string_view abbrevAscii = #ABBREV; \
923 static constexpr std::string_view symbol = ""; \
924 };

◆ MTCORE_DEF_UNIT_NAME_DIFF_US

#define MTCORE_DEF_UNIT_NAME_DIFF_US ( NS,
UNIT,
US_NAME,
ABBREV )
Value:
template<> \
struct UnitName<std::remove_cvref_t<decltype(NS::UNIT)>> { \
static constexpr std::string_view nameUs = #US_NAME; \
static constexpr std::string_view name = #UNIT; \
static constexpr std::string_view abbrev = #ABBREV; \
static constexpr std::string_view abbrevUs = #ABBREV; \
static constexpr std::string_view abbrevAscii = #ABBREV; \
static constexpr std::string_view symbol = ""; \
};

Definition at line 926 of file units/base.hpp.

926#define MTCORE_DEF_UNIT_NAME_DIFF_US(NS, UNIT, US_NAME, ABBREV) \
927 template<> \
928 struct UnitName<std::remove_cvref_t<decltype(NS::UNIT)>> { \
929 static constexpr std::string_view nameUs = #US_NAME; \
930 static constexpr std::string_view name = #UNIT; \
931 static constexpr std::string_view abbrev = #ABBREV; \
932 static constexpr std::string_view abbrevUs = #ABBREV; \
933 static constexpr std::string_view abbrevAscii = #ABBREV; \
934 static constexpr std::string_view symbol = ""; \
935 };

◆ MTCORE_DEF_UNIT_NAME_NO_ABBREV

#define MTCORE_DEF_UNIT_NAME_NO_ABBREV ( NS,
UNIT )
Value:
template<> \
struct UnitName<std::remove_cvref_t<decltype(NS::UNIT)>> { \
static constexpr std::string_view nameUs = #UNIT; \
static constexpr std::string_view name = #UNIT; \
static constexpr std::string_view abbrev = #UNIT; \
static constexpr std::string_view abbrevUs = #UNIT; \
static constexpr std::string_view abbrevAscii = #UNIT; \
static constexpr std::string_view symbol = ""; \
};

Definition at line 882 of file units/base.hpp.

882#define MTCORE_DEF_UNIT_NAME_NO_ABBREV(NS, UNIT) \
883 template<> \
884 struct UnitName<std::remove_cvref_t<decltype(NS::UNIT)>> { \
885 static constexpr std::string_view nameUs = #UNIT; \
886 static constexpr std::string_view name = #UNIT; \
887 static constexpr std::string_view abbrev = #UNIT; \
888 static constexpr std::string_view abbrevUs = #UNIT; \
889 static constexpr std::string_view abbrevAscii = #UNIT; \
890 static constexpr std::string_view symbol = ""; \
891 };

◆ MTCORE_DEF_UNIT_NAME_SI

#define MTCORE_DEF_UNIT_NAME_SI ( NS,
UNIT,
US_NAME,
ABBREV )
Value:
MTCORE_DEF_UNIT_NAME_DIFF_US(NS, UNIT, US_NAME, ABBREV) \
MTCORE_DEF_UNIT_NAME_SI_PREFIXES_SMALL(NS, UNIT, US_NAME, ABBREV) \
MTCORE_DEF_UNIT_NAME_SI_PREFIXES_LARGE(NS, UNIT, US_NAME, ABBREV)
#define MTCORE_DEF_UNIT_NAME_DIFF_US(NS, UNIT, US_NAME, ABBREV)

Definition at line 966 of file units/base.hpp.

966#define MTCORE_DEF_UNIT_NAME_SI(NS, UNIT, US_NAME, ABBREV) \
967 MTCORE_DEF_UNIT_NAME_DIFF_US(NS, UNIT, US_NAME, ABBREV) \
968 MTCORE_DEF_UNIT_NAME_SI_PREFIXES_SMALL(NS, UNIT, US_NAME, ABBREV) \
969 MTCORE_DEF_UNIT_NAME_SI_PREFIXES_LARGE(NS, UNIT, US_NAME, ABBREV)

◆ MTCORE_DEF_UNIT_NAME_SI_PREFIXES_LARGE

#define MTCORE_DEF_UNIT_NAME_SI_PREFIXES_LARGE ( NS,
UNIT,
US_NAME,
ABBREV )
Value:
MTCORE_DEF_UNIT_NAME_DIFF_US(NS, deca##UNIT, deca##US_NAME, da##ABBREV) \
MTCORE_DEF_UNIT_NAME_DIFF_US(NS, hecto##UNIT, hecto##US_NAME, hm##ABBREV) \
MTCORE_DEF_UNIT_NAME_DIFF_US(NS, kilo##UNIT, kilo##US_NAME, km##ABBREV) \
MTCORE_DEF_UNIT_NAME_DIFF_US(NS, mega##UNIT, mega##US_NAME, M##ABBREV) \
MTCORE_DEF_UNIT_NAME_DIFF_US(NS, giga##UNIT, giga##US_NAME, G##ABBREV) \
MTCORE_DEF_UNIT_NAME_DIFF_US(NS, tera##UNIT, tera##US_NAME, T##ABBREV) \
MTCORE_DEF_UNIT_NAME_DIFF_US(NS, peta##UNIT, peta##US_NAME, P##ABBREV)

Definition at line 957 of file units/base.hpp.

957#define MTCORE_DEF_UNIT_NAME_SI_PREFIXES_LARGE(NS, UNIT, US_NAME, ABBREV) \
958 MTCORE_DEF_UNIT_NAME_DIFF_US(NS, deca##UNIT, deca##US_NAME, da##ABBREV) \
959 MTCORE_DEF_UNIT_NAME_DIFF_US(NS, hecto##UNIT, hecto##US_NAME, hm##ABBREV) \
960 MTCORE_DEF_UNIT_NAME_DIFF_US(NS, kilo##UNIT, kilo##US_NAME, km##ABBREV) \
961 MTCORE_DEF_UNIT_NAME_DIFF_US(NS, mega##UNIT, mega##US_NAME, M##ABBREV) \
962 MTCORE_DEF_UNIT_NAME_DIFF_US(NS, giga##UNIT, giga##US_NAME, G##ABBREV) \
963 MTCORE_DEF_UNIT_NAME_DIFF_US(NS, tera##UNIT, tera##US_NAME, T##ABBREV) \
964 MTCORE_DEF_UNIT_NAME_DIFF_US(NS, peta##UNIT, peta##US_NAME, P##ABBREV)

◆ MTCORE_DEF_UNIT_NAME_SI_PREFIXES_SMALL

#define MTCORE_DEF_UNIT_NAME_SI_PREFIXES_SMALL ( NS,
UNIT,
US_NAME,
ABBREV )
Value:
MTCORE_DEF_UNIT_NAME_DIFF_US(NS, deci##UNIT, deci##US_NAME, d##ABBREV) \
MTCORE_DEF_UNIT_NAME_DIFF_US(NS, centi##UNIT, centi##US_NAME, c##ABBREV) \
MTCORE_DEF_UNIT_NAME_DIFF_US(NS, milli##UNIT, milli##US_NAME, m##ABBREV) \
MTCORE_DEF_UNIT_NAME_UNIC_ABB(NS, micro##UNIT, micro##US_NAME, u##ABBREV, μ##ABBREV) \
MTCORE_DEF_UNIT_NAME_DIFF_US(NS, nano##UNIT, nano##US_NAME, n##ABBREV) \
MTCORE_DEF_UNIT_NAME_DIFF_US(NS, pico##UNIT, pico##US_NAME, p##ABBREV) \
MTCORE_DEF_UNIT_NAME_DIFF_US(NS, femto##UNIT, femto##US_NAME, f##ABBREV)

Definition at line 948 of file units/base.hpp.

948#define MTCORE_DEF_UNIT_NAME_SI_PREFIXES_SMALL(NS, UNIT, US_NAME, ABBREV) \
949 MTCORE_DEF_UNIT_NAME_DIFF_US(NS, deci##UNIT, deci##US_NAME, d##ABBREV) \
950 MTCORE_DEF_UNIT_NAME_DIFF_US(NS, centi##UNIT, centi##US_NAME, c##ABBREV) \
951 MTCORE_DEF_UNIT_NAME_DIFF_US(NS, milli##UNIT, milli##US_NAME, m##ABBREV) \
952 MTCORE_DEF_UNIT_NAME_UNIC_ABB(NS, micro##UNIT, micro##US_NAME, u##ABBREV, μ##ABBREV) \
953 MTCORE_DEF_UNIT_NAME_DIFF_US(NS, nano##UNIT, nano##US_NAME, n##ABBREV) \
954 MTCORE_DEF_UNIT_NAME_DIFF_US(NS, pico##UNIT, pico##US_NAME, p##ABBREV) \
955 MTCORE_DEF_UNIT_NAME_DIFF_US(NS, femto##UNIT, femto##US_NAME, f##ABBREV)

◆ MTCORE_DEF_UNIT_NAME_STRS

#define MTCORE_DEF_UNIT_NAME_STRS ( NS,
UNIT,
NAME,
US_NAME,
ABBREV,
ABBREV_ASCII,
ABBREV_US,
SYMBOL )
Value:
template<> \
struct UnitName<std::remove_cvref_t<decltype(NS::UNIT)>> { \
static constexpr std::string_view nameUs = US_NAME; \
static constexpr std::string_view name = NAME; \
static constexpr std::string_view abbrev = ABBREV; \
static constexpr std::string_view abbrevUs = ABBREV; \
static constexpr std::string_view abbrevAscii = ABBREV_ASCII; \
static constexpr std::string_view symbol = SYMBOL; \
};

Definition at line 904 of file units/base.hpp.

904#define MTCORE_DEF_UNIT_NAME_STRS(NS, UNIT, NAME, US_NAME, ABBREV, ABBREV_ASCII, ABBREV_US, SYMBOL) \
905 template<> \
906 struct UnitName<std::remove_cvref_t<decltype(NS::UNIT)>> { \
907 static constexpr std::string_view nameUs = US_NAME; \
908 static constexpr std::string_view name = NAME; \
909 static constexpr std::string_view abbrev = ABBREV; \
910 static constexpr std::string_view abbrevUs = ABBREV; \
911 static constexpr std::string_view abbrevAscii = ABBREV_ASCII; \
912 static constexpr std::string_view symbol = SYMBOL; \
913 };

◆ MTCORE_DEF_UNIT_NAME_SYM

#define MTCORE_DEF_UNIT_NAME_SYM ( NS,
UNIT,
ABBREV,
SYM )
Value:
template<> \
struct UnitName<std::remove_cvref_t<decltype(NS::UNIT)>> { \
static constexpr std::string_view nameUs = #UNIT; \
static constexpr std::string_view name = #UNIT; \
static constexpr std::string_view abbrev = #ABBREV; \
static constexpr std::string_view abbrevUs = #ABBREV; \
static constexpr std::string_view abbrevAscii = #ABBREV; \
static constexpr std::string_view symbol = SYM; \
};

Definition at line 893 of file units/base.hpp.

893#define MTCORE_DEF_UNIT_NAME_SYM(NS, UNIT, ABBREV, SYM) \
894 template<> \
895 struct UnitName<std::remove_cvref_t<decltype(NS::UNIT)>> { \
896 static constexpr std::string_view nameUs = #UNIT; \
897 static constexpr std::string_view name = #UNIT; \
898 static constexpr std::string_view abbrev = #ABBREV; \
899 static constexpr std::string_view abbrevUs = #ABBREV; \
900 static constexpr std::string_view abbrevAscii = #ABBREV; \
901 static constexpr std::string_view symbol = SYM; \
902 };

◆ MTCORE_DEF_UNIT_NAME_UNIC_ABB

#define MTCORE_DEF_UNIT_NAME_UNIC_ABB ( NS,
UNIT,
US_NAME,
ABBREV,
UNIC_ABB )
Value:
template<> \
struct UnitName<std::remove_cvref_t<decltype(NS::UNIT)>> { \
static constexpr std::string_view nameUs = #US_NAME; \
static constexpr std::string_view name = #UNIT; \
static constexpr std::string_view abbrev = #UNIC_ABB; \
static constexpr std::string_view abbrevUs = #UNIC_ABB; \
static constexpr std::string_view abbrevAscii = #ABBREV; \
static constexpr std::string_view symbol = ""; \
};

Definition at line 937 of file units/base.hpp.

937#define MTCORE_DEF_UNIT_NAME_UNIC_ABB(NS, UNIT, US_NAME, ABBREV, UNIC_ABB) \
938 template<> \
939 struct UnitName<std::remove_cvref_t<decltype(NS::UNIT)>> { \
940 static constexpr std::string_view nameUs = #US_NAME; \
941 static constexpr std::string_view name = #UNIT; \
942 static constexpr std::string_view abbrev = #UNIC_ABB; \
943 static constexpr std::string_view abbrevUs = #UNIC_ABB; \
944 static constexpr std::string_view abbrevAscii = #ABBREV; \
945 static constexpr std::string_view symbol = ""; \
946 };