Comments (9)
In some ways both terms are lacking.
value()
implies that a unit consists of two separate parts, a container and a value which is contained. This is sort of the opposite of how I see units; in my mind units are trivial types, not containers. 3_m
is the value. Someday I want people to think of raw arithmetic types the same way they do for raw pointers, a.k.a. distasteful and best avoided (all things being equal). When that happens, value
starts to make less sense.
magnitude()
kind of makes sense (more so in boost/physunits which also have the quantity
syntax), but usually magnitude in physics implies no dimension or direction, so does it really make sense if the magnitude()
returned a negative value? It does have implications of being a mathematical transform, which I like.
operator()
is probably the worst, because of how often it requires a double-parenthesis ()()
syntax, and that it gives no context. The only merit is brevity.
unit_cast<...>()
to me is the most standard-ese. It's an explicit cast for a potentially unsafe operation, and it's reminiscent of std::chrono::duration_cast<...>()
. It makes it clear that you are losing something, and implies to readers (correctly) that something kludegy was happening for some reason. to<..>()
is basically just unit_cast
in member-function form.
Don't take these musings to mean that I've made a decision.
As far as standardization goes, I'd prefer the committee was making these types of calls instead of myself, but naming conventions are easily changed in the future std
fork so I'm not too worry about making the "wrong" decision in v2.3.0
.
from units.
easy enough. I'll think about it tonight and if there are no unintended consequences could roll it into a v2.2.1
.
You may not want it to be so easy to carry around .value()
though. Unless it's an interface boundary, I suspect unit_t<...>
can be used without conversion to arithmetic types in many more places than boost::units
.
I'm assuming that you're also already familiar with the fact that the underlying type can be accessed with operator()
, as well as the to<..>()
function, which will cast the value to any desired arithmetic type.
from units.
and if at all add it: s/value()
/magnitude()
/ ?
from units.
@martinmoene I think unless it matched the boost syntax exactly then there isn't any point? Since you can already get to the underlying value using:
operator()
(member)unit_cast<...>()
(static)to<...>()
(member)
from units.
from units.
Instead of thinking about backwards compatibility, I was thinking forward about standardization. In case one explicitly would want to use a quantity's magnitude, magnitude()
might better express that intent than value()
does. Just to have it mentioned.
from units.
from units.
from units.
I'm going to put this into the next version. I think overall it does no harm. Whether it's carried forward into a standardization proposal is another matter (and my recommendation would be that it isn't for the reasons already given; in fact I'd strip out all accessors aside from unit_cast
).
from units.
Related Issues (20)
- Undefined references to .name() and .abbreviation() HOT 1
- Incorrect enable_if condition for operator+ HOT 1
- Request for branch and pull request permissions HOT 5
- percent_t FROM double and TO double are different HOT 9
- 2.3.3 does not compile
- Add a way to specify units when "downcasting" to numeric type HOT 2
- Support the MSFS SDK HOT 2
- Empty base class optimization for MSVC
- Does not compile with GCC 12 HOT 1
- raw() and value() is error prone HOT 4
- [Bug] i386 (32-bit) fails to compile
- Shouldn't the naming of units::torque::foot_pound be changed
- v2 -> v3 porting HOT 2
- Need help implementing resistance as a new custom unit. HOT 2
- unit conversion emits a surprisingly high amount of instructions
- Compilation under MINGW
- Math functions not compatible with percent HOT 1
- Status of the project HOT 14
- Units are not installed as a system library HOT 1
- How to print units with C++20 std::format()? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from units.