|
Boost Users : |
Subject: Re: [Boost-users] Boost.Units: Is it possible to convert on assignment without casting?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2019-01-14 17:58:23
AMDG
On 1/14/19 1:50 AM, Carel Combrink via Boost-users wrote:
> I have two unit quantities defined as follow:
> static const auto Hz = boost::units::si::hertz;
> static const auto KHz = boost::units::si::kilo * Hz;
> using Hertz = boost::units::quantity<decltype( Hz ), double>;
> using Kilohertz = boost::units::quantity<decltype( KHz ), double>;
>
> Assigning one type to another does not compile:
> Kilohertz freqKhz = Kilohertz::from_value( 1.234 );
> Hertz freqHz = freqKhz;
This is not assignment. It uses the copy constructor
and requires an implicit conversion (which is forbidden
by design). Try direct construction, instead:
Hertz freqHz{freqKhz};
>>>> error: conversion from 'Kilohertz {aka boost::units::quantity<...>,
> double>}' to non-scalar type 'Hertz {aka boost::units::quantity<...>,
> double>}' requested [1]
>
> Is this possible, should it be enabled or is it not supported?
> I am using boost 01.67, Mingw 5.3 and MSVC 2017 (C++14)
> <snip>
>
In Christ,
Steven Watanabe
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