|
Boost : |
Subject: Re: [boost] [units] - learning to use
From: Matthias Schabel (boost_at_[hidden])
Date: 2011-11-27 21:52:27
> Try D/double(steps). Matthias, I seem to recall that the
> reason we disabled generic multiplication was that it
> was causing ambiguities with user defined types. Do
> you think it would be a good idea to enable arithmetic
> with any built-in arithmetic type?
I seem to remember that we ran into some conflicts, but I can't come up with a specific example
off the top of my head. I would be in favor of having arithmetic operations between quantities/units
and built in types behave in the expected way.
>> (***)
>> it seems strange that I need to take .value() here. The result is
>> dimensionless, why can't it directly convert to complex<double> ?
>> There is a risk that .value() would be expressed in millimeters or
>> angstroms or whatever (maybe depending on dd), and then .value()
>> would return a wrongly scaled number?
>>
>
> This is an idiosyncrasy of overload resolution.
> std::complex::operator+= is a template, so an
> implicit conversion doesn't work. The template
> argument can't be deduced.
Perhaps we should flesh out the toy complex implementation we wrote and incorporate it in the units library?
It is a fairly common thing to use together with units and, as I understand it, the standard only defines complex
for a subset of built in types...
>> Another question, why this works:
>>
>> quantity<length> wavelength ( 632.8 *nano*meters);
>>
>> and this does not?
>>
>> quantity<length> wavelength = 632.8 *nano*meters;
>>
>> Of course I know about extra copying, and waste of CPU resources on
>> execution, when compiler isn't able to optimize this away (and
>> usually it is able to do that). But why the heck this simple
>> assignment can't work?
>>
>
> This isn't assignment. It's copy construction and
> requires an implicit conversion which is forbidden.
Although, in Janek's defense, this seems overly restrictive. Can we allow copy construction between
scaled units and the corresponding unscaled unit without introducing undesirable side effects?
Matthias
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk