it’s better to:a) explicitly cast or specify type (in this case, declare std::size_t i)b) pass an explicit template argument
c) change the metaprogram (is boost::irange behavior really sensitive to this difference?)
(...)
suffixes shouldn’t be encouraged where better stylistic choices exist.
vector<int> vals{1,2,3,4,5,6,7,8,9,10,11,12,13};
auto product = accumulate(begin(vals), end(vals), 1, multiplies<>); //Probably undefined behavior!
auto product = accumulate(begin(vals), end(vals), (unsigned long long)1, multiplies<>);
Provided there is a postfix for unsigned long longs, I can just write:auto product = accumulate(begin(vals), end(vals), 1ull, multiplies<>);
auto product = accumulate(begin(vals), end(vals), (uint64_t)1, multiplies<>);
..but I don't have the second option now :(But unsigned long long is not a 'well defined' type, what if I want explicitly 64 bit calculations?..but I don't have the second option now :(auto product = accumulate(begin(vals), end(vals), (uint64_t)1, multiplies<>);
What second option? Can you elaborate what’s wrong with this line of code?
2014. július 20., vasárnap 3:48:54 UTC+2 időpontban David Krauss a következőt írta:What second option? Can you elaborate what’s wrong with this line of code?The one with a(n uint64_t) literal. There is nothing wrong with it, it's just nothing better than the one using casting to unsigned long long, but there the programmer has given a less verbose choice to write a literal, making unsigned long long a.. "more equal" citizen than uint64_t.
As a totally unlikely alternative, if it is actually an intention to use (unsigned long long)1 instead of 1ull, why not remove/deprecate the literal suffixes?
I like the idea, and use it in my own code (with an underscore of course). I typed up a proposal but didn't manage to get it done before the Urbana deadline, so it will have to wait until 2015. Here's the draft proposal
Does what I wrote seem reasonable?
Melissa