Opened 6 years ago
Last modified 6 years ago
#12766 new Feature Requests
Boost Units: Quantities in Constexpr Functions
| Reported by: | Owned by: | Jürgen Hunold | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | units |
| Version: | Boost 1.62.0 | Severity: | Problem |
| Keywords: | units literal constexpr | Cc: |
Description
I would like to use boost quantities in C++11 constexpr functions (and later C++14 constexpr functions). Unfurtunately, I can not define a simple quantity as constexpr:
#include <boost/units/systems/si.hpp>
#include <boost/units/quantity.hpp>
using namespace boost::units;
constexpr quantity< si::length, double > dtestExt{ 0.2e-6 };
// or
constexpr quantity< si::length, double > dtestExt = 0.2e-6;
g++ -std=c++11 (4.9.4):
error: the type ‘
const boost::units::quantity<
boost::units::unit<
boost::units::list<
boost::units::dim<
boost::units::length_base_dimension,
boost::units::static_rational<1l>
>,
boost::units::dimensionless_type
>,
boost::units::homogeneous_system<
boost::units::list<
boost::units::si::meter_base_unit,
boost::units::list<boost::units::scaled_base_unit<boost::units::cgs::gram_base_unit, boost::units::scale<10l, boost::units::static_rational<3l> > >,
boost::units::list<boost::units::si::second_base_unit, boost::units::list<boost::units::si::ampere_base_unit, boost::units::list<boost::units::si::kelvin_base_unit, boost::units::list<boost::units::si::mole_base_unit, boost::units::list<boost::units::si::candela_base_unit, boost::units::list<boost::units::angle::radian_base_unit, boost::units::list<boost::units::angle::steradian_base_unit, boost::units::dimensionless_type> > > > > >
>
>
>
>
>
>’
of constexpr variable ‘dtestExt’ is not literal
Note:
See TracTickets
for help on using tickets.

This might be solved by https://github.com/boostorg/units/pull/22 which unfortunately is missing tests.