[ Boost.Units ] Invert a quantity_type

Hi, I have a structure that is passed some type from which I can extract a units quantity type: template <typename Field> struct field { Field f; typedef typename Field::quantity_type quantity_type; // access typed data off Field quantity_type operator[](int i) { return f[i]; } }; Is there a way to invert a quantity type so I can compute and return, say, the inverse of the passed quantity_type? So, for example, is there any Boost.Units inverse meta like function that might let me say something like this: template <typename Field> struct field_inverse { Field f; typedef typename Field::quantity_type quantity_type; typedef typename bu::inverse<quantity_type>::type inverse_quantity_type; // access typed data off field, return inverse of quantity_type inverse_quantity_type operator[](int i) { return one / f[i]; } }; I’m hoping for something more general than partially specializing the bu::inverse method for each quantity I may want to invert. Any ideas? — Noel Belcourt

AMDG On 06/06/2017 05:12 PM, Belcourt, Kenneth via Boost-users wrote:
I have a structure that is passed some type from which I can extract a units quantity type:
<snip>
Is there a way to invert a quantity type so I can compute and return, say, the inverse of the passed quantity_type? So, for example, is there any Boost.Units inverse meta like function that might let me say something like this:
<snip> I’m hoping for something more general than partially specializing the bu::inverse method for each quantity I may want to invert. Any ideas?
There isn't a specific inverse function, but, shouldn't divide_typeof_helper work or power_typeof_helper<T, -1> work? (or better just use decltype) In Christ, Steven Watanabe

On Jun 8, 2017, at 1:51 PM, Steven Watanabe via Boost-users <boost-users@lists.boost.org> wrote:
AMDG
On 06/06/2017 05:12 PM, Belcourt, Kenneth via Boost-users wrote:
I have a structure that is passed some type from which I can extract a units quantity type:
<snip>
Is there a way to invert a quantity type so I can compute and return, say, the inverse of the passed quantity_type? So, for example, is there any Boost.Units inverse meta like function that might let me say something like this:
<snip> I’m hoping for something more general than partially specializing the bu::inverse method for each quantity I may want to invert. Any ideas?
There isn't a specific inverse function, but, shouldn't divide_typeof_helper work or power_typeof_helper<T, -1> work? (or better just use decltype)
Sure, thought about using the helper functions, but they’re all marked as non-public APIs. /// INTERNAL ONLY template<class System, class Dim, class X> struct divide_typeof_helper< X,unit<Dim,System> > So don’t want to depend on bu implementation details. As for decltype, that’s possibly a bridge too far for less experienced developers so, for now, I still prefer explicit typing where I can. I appreciate the help Steven, thanks for suggestions!
participants (2)
-
Belcourt, Kenneth
-
Steven Watanabe