mp-units icon indicating copy to clipboard operation
mp-units copied to clipboard

feat: customization point to define the components of a QuantityValue

Open JohelEGP opened this issue 4 years ago • 3 comments

This would be to resolve https://github.com/BobSteagall/wg21/issues/36 in this library.

The idea is to have a customization point similar to quantity_like_traits. It'd be something like quantity_value_traits, with a size for the number of components and an indexed observer for the components.

So given struct vector2d { int x; int y; }, you could specialize it:

struct units::quantity_value_traits<vector2d> {
  static constexpr int size{2};
  template<int I> int get(const vector2d&);
};

Very much like structured bindings. Then, the as-of-yet unnamed quantity_ prefixed wrapper would accept quantity_value_traits::size pairs of template parameter for the dimension/kind and unit of each component in order.

using quantity_vector2d = units::quantity_unnamed<si::dim_length, si::metre, si::dim_acceleration, si::metre_per_second, vector2d>;

JohelEGP avatar Feb 26 '21 22:02 JohelEGP

This'd be a generic solution, so expect ugly observers like get<0>(q), like std::tuple.

JohelEGP avatar Feb 26 '21 22:02 JohelEGP

I think I'd prefer to live with a variety of types with very similar definitions than use this. Each would be named appropriately (with improved error messages), and have the best observer like .x. Until we get metaclasses and can get rid of most of the repetition.

JohelEGP avatar Feb 26 '21 23:02 JohelEGP

Related to #23. I intend to do the homework based on https://github.com/mpusz/units/issues/23#issuecomment-589166416 soon.

mpusz avatar May 09 '21 21:05 mpusz