Boost logo

Boost Users :

Subject: [Boost-users] [ Boost.Units ] Invert a quantity_type
From: Belcourt, Kenneth (kbelco_at_[hidden])
Date: 2017-06-06 23:12:02


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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net