nholthaus / units

a compile-time, header-only, dimensional analysis and unit conversion library built on c++14 with no dependencies.
http://nholthaus.github.io/units/
MIT License
934 stars 134 forks source link

Support for `constexpr` declaration of the Negative values with literals #293

Open jinay1991 opened 1 year ago

jinay1991 commented 1 year ago

It was often required to define certain constants statically and preferably as constexpr, although there are certain times, values may need to be -ve. This is already possible with full declaration of the unit, although does not support alongside the literals. Please see example below:

static constexpr units::angle::radian_t kAngularValue{-30.0_deg};  /// ERROR: Compiler will not find `constexpr`
                                                                   /// definition of the literal to convert deg to
                                                                   /// radian implicitly for negative numbers.

static constexpr units::angle::radian_t kAngularValue = units::angle::degree_t{-30.0};  /// WORKS FINE
static constexpr units::angle::radian_t kAngularValue{30.0_deg};                        /// WORKS FINE

I request the FIX or SUPPORT for such use-case.

Thanks in advance.

Library Version: v2.3.1 Compiler Used: GCC v12, Clang v12

nholthaus commented 1 year ago

supported in the 3.0 releases. Consider backporting to 2.3.