xo-unit: + numeric_concept + unit_concept
This commit is contained in:
parent
4d823595fe
commit
b4c3ba4dda
3 changed files with 89 additions and 1 deletions
38
include/xo/unit/numeric_concept.hpp
Normal file
38
include/xo/unit/numeric_concept.hpp
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/* @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
|
||||
* - boost::rational<U>
|
||||
* - std::complex<U>
|
||||
* - xo::unit::quantity<U,R>
|
||||
*
|
||||
* This implies we don't require T to be totally ordered,
|
||||
* and don't require (<,<=,>=,>) operators.
|
||||
*
|
||||
* 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 */
|
||||
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <concepts>
|
||||
#include "unit_concept.hpp"
|
||||
#include "numeric_concept.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace unit {
|
||||
|
|
|
|||
49
include/xo/unit/unit_concept.hpp
Normal file
49
include/xo/unit/unit_concept.hpp
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/* @file unit_concept.hpp */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "dimension_concept.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace unit {
|
||||
/** @brief concept for a Unit type, suitable for use with the quantity template
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* using namespace xo::unit;
|
||||
* static_assert(unit_concept<units::day>);
|
||||
* @endcode
|
||||
**/
|
||||
template <typename Unit>
|
||||
concept unit_concept = requires(Unit unit)
|
||||
{
|
||||
typename Unit::scalefactor_type;
|
||||
typename Unit::dim_type;
|
||||
typename Unit::canon_type;
|
||||
}
|
||||
&& (ratio_concept<typename Unit::scalefactor_type>
|
||||
&& bpu_list_concept<typename Unit::dim_type>
|
||||
&& bpu_list_concept<typename Unit::canon_type>);
|
||||
|
||||
|
||||
/** @brief concept for a Unit type, that contains exactly one basis dimension
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* using namespace xo::unit
|
||||
* static_assert(basis_unit_concept<units::volatility_250d>);
|
||||
* @endcode
|
||||
**/
|
||||
template <typename Unit>
|
||||
concept basis_unit_concept = requires(Unit unit)
|
||||
{
|
||||
typename Unit::dim_type;
|
||||
typename Unit::dim_type::rest_type;
|
||||
}
|
||||
&& (std::same_as<typename Unit::dim_type::rest_type, void>)
|
||||
&& (unit_concept<Unit>);
|
||||
} /*namespace unit*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
||||
/* end unit_concept.hpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue