xo-unit: refactor: dup mpl shared files to prep namespace change
This commit is contained in:
parent
e44bf2aad3
commit
67e26a426f
2 changed files with 116 additions and 0 deletions
82
include/xo/unit/mpl/dim_util.hpp
Normal file
82
include/xo/unit/mpl/dim_util.hpp
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/* @file dim_util.hpp */
|
||||
|
||||
#pragma once
|
||||
|
||||
//#include "stringliteral.hpp"
|
||||
//#include "xo/flatstring/flatstring.hpp"
|
||||
#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
namespace unit {
|
||||
enum class dim {
|
||||
invalid = -1,
|
||||
|
||||
/** weight. native unit = 1 gram **/
|
||||
mass,
|
||||
/** distance. native unit = 1 meter **/
|
||||
distance,
|
||||
/** time. native unit = 1 second **/
|
||||
time,
|
||||
/** a currency amount. native unit depends on actual currency.
|
||||
* For USD: one US dollar.
|
||||
*
|
||||
* NOTE: unit system isn't suitable for multicurrency work:
|
||||
* (1usd + 1eur) is well-defined, but (1sec + 1m) is not.
|
||||
**/
|
||||
currency,
|
||||
/** a screen price **/
|
||||
price,
|
||||
|
||||
/** comes last, counts entries **/
|
||||
n_dim
|
||||
};
|
||||
|
||||
inline const char *
|
||||
dim2str(dim x)
|
||||
{
|
||||
switch(x) {
|
||||
case dim::mass: return "mass";
|
||||
case dim::distance: return "distance";
|
||||
case dim::time: return "time";
|
||||
case dim::currency: return "currency";
|
||||
case dim::price: return "price";
|
||||
default: break;
|
||||
}
|
||||
return "?dim";
|
||||
}
|
||||
|
||||
static constexpr std::size_t n_dim = static_cast<std::size_t>(dim::n_dim);
|
||||
|
||||
enum class native_unit_id {
|
||||
gram,
|
||||
meter,
|
||||
second,
|
||||
currency,
|
||||
price
|
||||
};
|
||||
|
||||
template <dim Dim>
|
||||
struct native_unit_for;
|
||||
|
||||
template <>
|
||||
struct native_unit_for<dim::mass> { static constexpr auto value = native_unit_id::gram; };
|
||||
|
||||
template <>
|
||||
struct native_unit_for<dim::distance> { static constexpr auto value = native_unit_id::meter; };
|
||||
|
||||
template <>
|
||||
struct native_unit_for<dim::time> { static constexpr auto value = native_unit_id::second; };
|
||||
|
||||
template <>
|
||||
struct native_unit_for<dim::currency> { static constexpr auto value = native_unit_id::currency; };
|
||||
|
||||
template <>
|
||||
struct native_unit_for<dim::price> { static constexpr auto value = native_unit_id::price; };
|
||||
|
||||
template <dim Dim>
|
||||
constexpr auto native_unit_for_v = native_unit_for<Dim>::value;
|
||||
|
||||
} /*namespace unit*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end dim_util.hpp */
|
||||
34
include/xo/unit/mpl/numeric_concept.hpp
Normal file
34
include/xo/unit/mpl/numeric_concept.hpp
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* @file numeric_concept.hpp */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <concepts>
|
||||
|
||||
namespace xo {
|
||||
namespace unit {
|
||||
/** @concept numeric_concept
|
||||
* @brief Concept for values that participate in arithmetic operations (+,-,*,/) and comparisons
|
||||
*
|
||||
* Intended to include at least:
|
||||
* - built-in integral and floating-point types
|
||||
* - xo::raio<U>
|
||||
* - xo::unit::quantity<U,R>
|
||||
*
|
||||
* Intend numeric_concept to apply to types suitable for
|
||||
* xo::unit::quantity::repr_type.
|
||||
**/
|
||||
template <typename T, typename U = T>
|
||||
concept numeric_concept = requires(T x, U y)
|
||||
{
|
||||
{ -x };
|
||||
{ x - y };
|
||||
{ x + y };
|
||||
{ x * y };
|
||||
{ x / y };
|
||||
{ x == y };
|
||||
{ x != y };
|
||||
};
|
||||
} /*namespace unit*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end numeric_concept.hpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue