-
Hi! inline constexpr struct point final
: mp_units::named_unit<"point", mp_units::kind_of<mp_units::isq::length>> {
} point;
inline constexpr struct pixel final
: mp_units::named_unit<"pixel", mp_units::kind_of<mp_units::isq::length>> {
} pixel; So far so good, I can use it in my types and it seems to work as intended. However, I am trying to do a 'rectangle-of-unit'. So essentially: template <typename T, auto R>
concept is_rectangle_of = requires(T&& t) {
{ left_x(std::forward<T>(t)) } -> /*is-quantity-point-with-unit-R-and-isq::width*/
/*...*/
};
template <typename U, typename Rep>
class basic_rectangle {
/*omit definition of basic*/
};
static_assert(is_rectangle_of<basic_rectangle<pixel, float>, pixel>);
static_assert(is_rectangle_of<basic_rectangle<point, int>, point>);
static_assert(!is_rectangle_of<basic_rectangle<pixel, int>, point>); I am struggling with this however. I am unsure if I am doing something wrong with the units or simply doesn't understand the I've tried:
but |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @doocman! Thanks for bringing this example here. I think there is a solution for your case here: https://godbolt.org/z/E1Pr3ohWT. Please let me know if it helps. The main issue you had was that To summarize, you need to implement your concept like this: template <typename QP, auto R>
concept is_quantity_point_of = Reference<decltype(R)> &&
QuantityPointOf<std::remove_cvref_t<QP>, get_quantity_spec(R)> &&
(QP::unit == get_unit(R)); |
Beta Was this translation helpful? Give feedback.
Hi @doocman!
Thanks for bringing this example here. I think there is a solution for your case here: https://godbolt.org/z/E1Pr3ohWT. Please let me know if it helps.
The main issue you had was that
QuantityOf
andQuantityPointOf
do not takeReference
as an argument. Checking if something is a length inmeters
orkilometers
is not particularly useful in generic algorithms. What is important here is that something is a quantity of length, and this is the semantics we provide. Checking against a specific unit is very simple if you need that.To summarize, you need to implement your concept like this: