Tuesday, November 28, 2017

Digest for comp.lang.c++@googlegroups.com - 13 updates in 4 topics

"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Nov 28 05:42PM +0100

> a mantissa corresponding to processing this string argument with a
> function strtod...
 
> I only have one question ... Why would this be necessary ???
 
With IEEE 754, which is the most common floating point format, there is
not one single NaN value, but a multitude. ¹`std::nan()` gives you an
implementation-defined way to generate specific values of that
multitude, when the floating point format supports NaN.
²`std::numeric_limits<T>::quiet_NaN`, with `T` a floating point type,
gives you a particular one of those values; in practice it's the one
that gives the cleanest text representation, just "NaN".
 
To check for NaN-value, with modern compilers as of 2017 use ³`std::isnan`.
 
With older compilers it was difficult to check for NaN-value. One could
not and can still not rely on NaN != NaN, because when you ask the
compiler (e.g. g++, Visual C++) to optimize floating point operations
it's likely to optimize away that special behavior of NaN. Just keep in
mind that NaN is VERY tricky and slippery and a joker, like Loki.
 
Cheers & hth.,
 
- Alf
 
Links:
¹ http://en.cppreference.com/w/cpp/numeric/math/nan
² http://en.cppreference.com/w/cpp/types/numeric_limits/quiet_NaN
³ http://en.cppreference.com/w/cpp/numeric/math/isnan
Chris Ahlstrom <OFeem1987@teleworm.us>: Nov 28 04:39PM -0500

Alf P. Steinbach wrote this copyrighted missive and expects royalties:
 
> compiler (e.g. g++, Visual C++) to optimize floating point operations
> it's likely to optimize away that special behavior of NaN. Just keep in
> mind that NaN is VERY tricky and slippery and a joker, like Loki.
 
Loki, Not a Norse god?
- - -
 
--
After all, all he did was string together a lot of old, well-known quotations.
-- H. L. Mencken, on Shakespeare
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Nov 28 11:56PM +0100

On 11/28/2017 10:39 PM, Chris Ahlstrom wrote:
>> it's likely to optimize away that special behavior of NaN. Just keep in
>> mind that NaN is VERY tricky and slippery and a joker, like Loki.
> Loki, Not a Norse god?
 
https://en.wikipedia.org/wiki/Loki
 
That is, the Norse being, not the library.
 
Cheers!,
 
- Alf
Vir Campestris <vir.campestris@invalid.invalid>: Nov 28 09:25PM

This code fragment
{
struct s { int a; int b;};
std::vector<s> foo;
foo.push_back({1,2});
foo.emplace_back({3,4});
}
when built with GCC, the push_back line works fine, but the emplace_back
one doesn't. WTH?
 
Andy
"Öö Tiib" <ootiib@hot.ee>: Nov 28 02:09PM -0800

On Tuesday, 28 November 2017 23:26:01 UTC+2, Vir Campestris wrote:
> }
> when built with GCC, the push_back line works fine, but the emplace_back
> one doesn't. WTH?
 
Not sure what you ask. Can you tell what you expected and why?
The emplace_back accepts and forwards constructor arguments of s.
The push_back accepts rvalue reference to s or reference to const s.
 
There are 3 constructors of your s so those work ...
 
foo.emplace_back(); // no arguments - default constructor
s const kaka{};
foo.emplace_back(kaka); // reference to const s - copy constructor
foo.emplace_back(s{3,4}); // rvalue reference to s - move constructor
 
Those however don't work ...
 
foo.emplace_back({3,4}); // std::initializer_list<int> - WTF?
foo.emplace_back(3,4); // two ints - WTF?
foo.emplace_back(foo); // std::vector<s> - WTF?
"James R. Kuyper" <jameskuyper@verizon.net>: Nov 28 11:36AM -0500

On 11/28/2017 12:40 AM, Alf P. Steinbach wrote:
>> return 0;
>> }
 
> No-one names a namespace `std`.
 
I'm not interested in common practice. Does the standard say anything to
prohibit a user-defined namespace named "std" anywhere other than the
global namespace? I looked, and couldn't find any such prohibition - but
it's a big, complex standard, and I might not have looked in the right
location.
"James R. Kuyper" <jameskuyper@verizon.net>: Nov 28 11:39AM -0500

On 11/28/2017 03:47 AM, David Brown wrote:
> program is undefined if it adds declarations or definitions to namespace
> std or to a
> namespace within namespace std unless otherwise specified.
 
That does not cover the case of a user-defined namespace named std
within a user-defined namespace.
Bo Persson <bop@gmb.dk>: Nov 28 06:32PM +0100

On 2017-11-28 17:36, James R. Kuyper wrote:
> global namespace? I looked, and couldn't find any such prohibition - but
> it's a big, complex standard, and I might not have looked in the right
> location.
 
The standard also doesn't say that you shouldn't pee in your bed, or not
jump off a cliff. Still bad ideas.
 
The standard practice IS that if you do this, and your co-workers find
that out after days of debugging - they are likely to bring their
baseball bats when they come visit you.
 
So just don't do this!
 
 
 
Bo Persson
"James R. Kuyper" <jameskuyper@verizon.net>: Nov 28 12:49PM -0500

On 11/28/2017 12:32 PM, Bo Persson wrote:
>> location.
 
> The standard also doesn't say that you shouldn't pee in your bed, or not
> jump off a cliff. Still bad ideas.
 
The fact that it's a bad idea (which I fully agree with) is irrelevant
to the point I'm asking about.
legalize+jeeves@mail.xmission.com (Richard): Nov 28 06:29PM

[Please do not mail me a copy of your followup]
 
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> spake the secret code
 
>But that doesn't mean that Leigh is right about `using namespace std;`
>always being ungood. [...]
 
There's one case where I thought it was mandatory: allowing ADL to
select between your custom implementation of swap and std::swap.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Terminals Wiki <http://terminals-wiki.org>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
"Öö Tiib" <ootiib@hot.ee>: Nov 28 10:34AM -0800

On Tuesday, 28 November 2017 19:49:53 UTC+2, James R. Kuyper wrote:
> > jump off a cliff. Still bad ideas.
 
> The fact that it's a bad idea (which I fully agree with) is irrelevant
> to the point I'm asking about.
 
To my knowledge standard does not reserve the name std. It even says that
fully qualified name of any name x of standard library is ::std::x unless explicitly described otherwise.
 
Usage of the name std for anything can in practice still get ones work
contract ended as deliberately confusing others and hampering team-work.
"Öö Tiib" <ootiib@hot.ee>: Nov 28 10:48AM -0800

On Tuesday, 28 November 2017 20:29:24 UTC+2, Richard wrote:
> >always being ungood. [...]
 
> There's one case where I thought it was mandatory: allowing ADL to
> select between your custom implementation of swap and std::swap.
 
The examples in standard about swappability seem all to use
"using std::swap;" for that purpose (instead of "using namespace std;"
or "using ::std::swap;")
"James R. Kuyper" <jameskuyper@verizon.net>: Nov 28 11:57AM -0500

On 11/28/2017 03:24 AM, David Brown wrote:
> three things you /don't/ want - one is for the user to have to supply a
> long list of type attributes manually, when it is easy for them to make
> mistakes. The next is to have complex logic like Ben showed you needed,
 
Did you mean "James" rather than "Ben"?
 
> since it is easy for /you/ to make mistakes. And the third is to have
> it all done at run-time instead of compile-time.
 
> I am still not sure of what your use-cases are here.
 
The use case appears to be exposition: using a C++ logical expression to
express the relevant rules. I don't believe there was any intention to
actually compile and execute this code.
 
In principle, a conceptually similar function could play a useful role
in a compiler. I've never designed a compiler, so I can't be sure, but
I'd expect that any such function would work in a much different manner
than this one. I'd expect there to be a class with instances that
contain the representation, in the compiler, of a particular type used
in a C++ program. That class would have derived classes for different
categories of types, and either the base class or some of the derived
classes might be templated. For the derived class used to describe class
types, for each special member function that could be implicitly
declared for the described type, there would be a member function which
determines whether it is implicitly declared, and if so, if it is
declared as deleted. That member function would involve different code
depending upon whether the described type was a union, a union-like
class, or non-union. It would involve recursive iteration over the
members of the described class. If any one of the problematic cases
listed in the standard comes up during that iteration, the function is
implicitly declared as deleted.
 
But I think you
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: