Skip to content

Commit

Permalink
refactor: 💥 ReferenceOf does not take a dimension anymore
Browse files Browse the repository at this point in the history
It seems unneeded and removing this check greatly simplifies common compilation errors.
  • Loading branch information
mpusz committed Jan 19, 2024
1 parent 81871bf commit b4f07f6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 43 deletions.
18 changes: 7 additions & 11 deletions docs/users_guide/framework_basics/concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,8 @@ A `Reference` can either be:

### `ReferenceOf<T, V>` { #ReferenceOf }

`ReferenceOf` concept is satisfied by references `T` that match the following value `V`:

| `V` | Condition |
|----------------|-----------------------------------------------------------------------------------------------|
| `Dimension` | The dimension of a quantity specification satisfies [`DimensionOf<V>`](#DimensionOf) concept. |
| `QuantitySpec` | The quantity specification satisfies [`QuantitySpecOf<V>`](#QuantitySpecOf) concept. |
`ReferenceOf` concept is satisfied by references `T` which have a quantity specification that satisfies
[`QuantitySpecOf<V>`](#QuantitySpecOf) concept. |


## `Representation<T>` { #Representation }
Expand Down Expand Up @@ -212,7 +208,7 @@ satisfied by all types being or deriving from an instantiation of a `quantity` c

### `QuantityOf<T, V>` { #QuantityOf }

`QuantityOf` concept is satisfied by all the quantities for which a [`ReferenceOf<V>`](#ReferenceOf)
`QuantityOf` concept is satisfied by all the quantities for which a [`QuantitySpecOf<V>`](#QuantitySpecOf)
is `true`.


Expand Down Expand Up @@ -259,10 +255,10 @@ class template.

`QuantityPointOf` concept is satisfied by all the quantity points `T` that match the following value `V`:

| `V` | Condition |
|---------------|----------------------------------------------------------------------------------|
| `Reference` | The quantity point reference satisfies [`ReferenceOf<V>`](#ReferenceOf) concept. |
| `PointOrigin` | The _point_ and `V` have the same absolute point origin. |
| `V` | Condition |
|----------------|-----------------------------------------------------------------------------------------------------|
| `QuantitySpec` | The quantity point quantity specification satisfies [`QuantitySpecOf<V>`](#QuantitySpecOf) concept. |
| `PointOrigin` | The _point_ and `V` have the same absolute point origin. |


## `QuantityLike<T>` { #QuantityLike }
Expand Down
10 changes: 5 additions & 5 deletions src/core/include/mp-units/bits/quantity_concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ template<typename T>
concept Quantity = detail::is_derived_from_specialization_of_quantity<T>;

/**
* @brief A concept matching all quantities with provided dimension or quantity spec
* @brief A concept matching all quantities with provided quantity spec
*
* Satisfied by all quantities with a dimension/quantity_spec being the instantiation derived from
* the provided dimension/quantity_spec type.
* Satisfied by all quantities with a quantity_spec being the instantiation derived from
* the provided quantity_spec type.
*/
template<typename Q, auto V>
concept QuantityOf = Quantity<Q> && ReferenceOf<std::remove_const_t<decltype(Q::reference)>, V>;
template<typename Q, auto QS>
concept QuantityOf = Quantity<Q> && QuantitySpecOf<std::remove_const_t<decltype(Q::quantity_spec)>, QS>;

/**
* @brief A concept matching all external quantities like types
Expand Down
8 changes: 4 additions & 4 deletions src/core/include/mp-units/bits/quantity_point_concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ concept SameAbsolutePointOriginAs =


/**
* @brief A concept matching all quantity points with provided dimension or quantity spec
* @brief A concept matching all quantity points with provided quantity spec
*
* Satisfied by all quantity points with a dimension/quantity_spec being the instantiation derived from
* the provided dimension/quantity_spec type, or quantity points having the origin with the same
* Satisfied by all quantity points with a quantity_spec being the instantiation derived from
* the provided quantity_spec type, or quantity points having the origin with the same
* `absolute_point_origin`.
*/
template<typename QP, auto V>
concept QuantityPointOf =
QuantityPoint<QP> && (ReferenceOf<std::remove_const_t<decltype(QP::reference)>, V> ||
QuantityPoint<QP> && (QuantitySpecOf<std::remove_const_t<decltype(QP::quantity_spec)>, V> ||
detail::SameAbsolutePointOriginAs<std::remove_const_t<decltype(QP::absolute_point_origin)>, V>);

/**
Expand Down
12 changes: 5 additions & 7 deletions src/core/include/mp-units/bits/reference_concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,12 @@ template<auto Q, auto U>
}

/**
* @brief A concept matching all references with provided dimension or quantity spec
* @brief A concept matching all references with provided quantity spec
*
* Satisfied by all references with a dimension/quantity_spec being the instantiation derived from
* the provided dimension/quantity_spec type.
* Satisfied by all references with a quantity_spec being the instantiation derived from
* the provided quantity_spec type.
*/
template<typename T, auto V>
concept ReferenceOf =
Reference<T> && (DimensionOf<std::remove_const_t<decltype(get_quantity_spec(T{}).dimension)>, V> ||
QuantitySpecOf<std::remove_const_t<decltype(get_quantity_spec(T{}))>, V>);
template<typename T, auto QS>
concept ReferenceOf = Reference<T> && QuantitySpecOf<std::remove_const_t<decltype(get_quantity_spec(T{}))>, QS>;

} // namespace mp_units
22 changes: 6 additions & 16 deletions test/static/concepts_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ static_assert(!Dimension<base_dimension<"L">>);
static_assert(!Dimension<struct si::metre>);
static_assert(!Dimension<int>);

// DimensionOf
// TODO add tests

// QuantitySpec
struct speed : decltype(isq::length / isq::time) {}; // this is not recommended

Expand Down Expand Up @@ -132,6 +135,9 @@ static_assert(!detail::QuantityKindSpec<speed>);
static_assert(!detail::QuantityKindSpec<struct isq::dim_length>);
static_assert(!detail::QuantityKindSpec<int>);

// QuantitySpecOf
// TODO add tests

// Unit
struct metre_per_second : decltype(si::metre / si::second) {};

Expand Down Expand Up @@ -265,24 +271,16 @@ static_assert(ReferenceOf<std::remove_const_t<decltype(isq::length[si::metre])>,
static_assert(!ReferenceOf<std::remove_const_t<decltype(isq::length[si::metre])>, isq::radius>);
static_assert(ReferenceOf<std::remove_const_t<decltype(isq::radius[si::metre])>, isq::length>);
static_assert(ReferenceOf<std::remove_const_t<decltype(isq::radius[si::metre])>, isq::radius>);
static_assert(ReferenceOf<struct si::metre, isq::dim_length>);
static_assert(!ReferenceOf<struct si::second, isq::dim_length>);
static_assert(ReferenceOf<std::remove_const_t<decltype(isq::length[si::metre])>, isq::dim_length>);
static_assert(ReferenceOf<std::remove_const_t<decltype(isq::radius[si::metre])>, isq::dim_length>);

static_assert(ReferenceOf<struct one, dimensionless>);
static_assert(ReferenceOf<struct one, dimension_one>);
static_assert(ReferenceOf<std::remove_const_t<decltype(dimensionless[one])>, dimensionless>);
static_assert(ReferenceOf<std::remove_const_t<decltype(dimensionless[one])>, dimension_one>);
static_assert(ReferenceOf<std::remove_const_t<decltype(isq::rotation[one])>, isq::rotation>);
static_assert(ReferenceOf<std::remove_const_t<decltype(isq::rotation[one])>, dimensionless>);
static_assert(ReferenceOf<std::remove_const_t<decltype(isq::rotation[one])>, dimension_one>);
static_assert(ReferenceOf<struct si::radian, isq::angular_measure>);
static_assert(!ReferenceOf<struct si::radian, dimensionless>);
static_assert(ReferenceOf<struct si::radian, dimension_one>);
static_assert(ReferenceOf<std::remove_const_t<decltype(isq::angular_measure[si::radian])>, isq::angular_measure>);
static_assert(!ReferenceOf<std::remove_const_t<decltype(isq::angular_measure[si::radian])>, dimensionless>);
static_assert(ReferenceOf<std::remove_const_t<decltype(isq::angular_measure[si::radian])>, dimension_one>);
static_assert(ReferenceOf<struct one, isq::rotation>);
static_assert(ReferenceOf<struct one, isq::angular_measure>);
static_assert(!ReferenceOf<std::remove_const_t<decltype(dimensionless[one])>, isq::rotation>);
Expand Down Expand Up @@ -323,24 +321,16 @@ static_assert(QuantityOf<quantity<isq::length[si::metre]>, isq::length>);
static_assert(!QuantityOf<quantity<isq::length[si::metre]>, isq::radius>);
static_assert(QuantityOf<quantity<isq::radius[si::metre]>, isq::length>);
static_assert(QuantityOf<quantity<isq::radius[si::metre]>, isq::radius>);
static_assert(QuantityOf<quantity<si::metre>, isq::dim_length>);
static_assert(!QuantityOf<quantity<si::second>, isq::dim_length>);
static_assert(QuantityOf<quantity<isq::length[si::metre]>, isq::dim_length>);
static_assert(QuantityOf<quantity<isq::radius[si::metre]>, isq::dim_length>);

static_assert(QuantityOf<quantity<one>, dimensionless>);
static_assert(QuantityOf<quantity<one>, dimension_one>);
static_assert(QuantityOf<quantity<dimensionless[one]>, dimensionless>);
static_assert(QuantityOf<quantity<dimensionless[one]>, dimension_one>);
static_assert(QuantityOf<quantity<isq::rotation[one]>, isq::rotation>);
static_assert(QuantityOf<quantity<isq::rotation[one]>, dimensionless>);
static_assert(QuantityOf<quantity<isq::rotation[one]>, dimension_one>);
static_assert(QuantityOf<quantity<si::radian>, isq::angular_measure>);
static_assert(!QuantityOf<quantity<si::radian>, dimensionless>);
static_assert(QuantityOf<quantity<si::radian>, dimension_one>);
static_assert(QuantityOf<quantity<isq::angular_measure[si::radian]>, isq::angular_measure>);
static_assert(!QuantityOf<quantity<isq::angular_measure[si::radian]>, dimensionless>);
static_assert(QuantityOf<quantity<isq::angular_measure[si::radian]>, dimension_one>);
static_assert(QuantityOf<quantity<one>, isq::rotation>);
static_assert(QuantityOf<quantity<one>, isq::angular_measure>);
static_assert(!QuantityOf<quantity<dimensionless[one]>, isq::rotation>);
Expand Down

0 comments on commit b4f07f6

Please sign in to comment.