Thursday, November 30, 2017

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

Bob <user@foobar.com.invalid>: Nov 30 02:12AM

Not a homework problem, too dumb for school.
https://forum.level1techs.com/t/c-openmp/121868
"Öö Tiib" <ootiib@hot.ee>: Nov 29 11:00PM -0800

On Thursday, 30 November 2017 04:12:48 UTC+2, Bob wrote:
> Not a homework problem, too dumb for school.
> https://forum.level1techs.com/t/c-openmp/121868
 
It hangs or crashes or what means "dies" and where?
Can't you run it in debugger?
"Necron_99" <user@foobar.com.invalid>: Nov 30 03:06PM

=?UTF-8?B?w5bDtiBUaWli?= <ootiib@hot.ee> wrote in news:1a39d558-c400-4cad-bdfc-
>> https://forum.level1techs.com/t/c-openmp/121868
 
> It hangs or crashes or what means "dies" and where?
> Can't you run it in debugger?
 
I've run smaller values of n in valgrind, no leaks detected. It dies during execution of the openp for
section. Anyway I'm following up on some suggestions I got over at
https://forum.level1techs.com/t/c-openmp/121868
"Öö Tiib" <ootiib@hot.ee>: Nov 30 09:24AM -0800

On Thursday, 30 November 2017 17:07:07 UTC+2, Necron_99 wrote:
> during execution of the openp for section. Anyway I'm following up
> on some suggestions I got over at
> https://forum.level1techs.com/t/c-openmp/121868
 
Still no answer what means "dies"? Programs are not alive so can't die.
Christian Gollwitzer <auriocus@gmx.de>: Nov 30 11:59PM +0100

Am 30.11.2017 um 03:12 schrieb Bob:
> Not a homework problem, too dumb for school.
> https://forum.level1techs.com/t/c-openmp/121868
 
You manipulate "x" (is this a global std::vector?) inside of
randomSample(). This is called in your openMP-loop and will therefore
execute in parallel. This can't work. You need to make sure that the
same object is not touched simultaneously from multiple threads. Either
protect with locks (lock_guard<>), or duplicate the vector. And even
better, remove the global. It is not sure where it is coming from, since
you don't show complete compilable code.
 
Christian
Josef Moellers <josef.moellers@invalid.invalid>: Nov 30 04:37PM +0100

I have written a small Qt program which displays a set of topics
subscribed from a mosquitto broker. At present, the program uses
libmosquitto, but I'd like to make it use libmosquittopp (it is also a
learning exercise).
The set of topics is not static, the topics are passed on the command
line, so I need a means to hand this set (forged into a QStringList) to
the on_connect() method in order to subscribe to all the topics given.
 
There is the user_data_set(void *userdata) method in the class
mosquittopp but it only passes the "userdata"-pointer to the underlying
mosquitto code. Any callback specified by
mosquitto_connect_callback_set() will then get this pointer but not the
on_connect() method!
 
Any hints?
 
Thanks,
Josef
"Öö Tiib" <ootiib@hot.ee>: Nov 30 08:32AM -0800

On Thursday, 30 November 2017 17:37:51 UTC+2, Josef Moellers wrote:
> mosquitto_connect_callback_set() will then get this pointer but not the
> on_connect() method!
 
> Any hints?
 
Very interesting. We are here on comp.lang.c++ discussing C++
language itself. With C++ it is possible to integrate anything with
anything but from your post it is not very clear what the issue is.
Is with mosquitto or with Qt or with your own C++ code?
 
To difficulties with mosquitto you perhaps get best hints from
https://groups.google.com/forum/#!forum/mqtt
 
To difficulties with Qt you get perhaps best hints at
https://forum.qt.io
 
If it is your own code that causes trouble then we can likely help
but can you give us illustrating example of the problem without
using neither Qt nor mosquitto?
Josef Moellers <josef.moellers@invalid.invalid>: Nov 30 06:56PM +0100

On 30.11.2017 17:32, Öö Tiib wrote:
> language itself. With C++ it is possible to integrate anything with
> anything but from your post it is not very clear what the issue is.
> Is with mosquitto or with Qt or with your own C++ code?
 
It is actually with the mosquitto code. I searched the list of
newsgroups my provider has and it had nothing that adressed this issue,
so I tried here. I'll go where you told me to go:
 
> To difficulties with mosquitto you perhaps get best hints from
> https://groups.google.com/forum/#!forum/mqtt
Sorry for the inconvenience,
 
Josef
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Nov 30 06:21AM -0800

As the years go by and more and more previously commercial (and even
open source) software makes the move into abandonware, where the original
copyright and/or patent holder is no longer maintaining or developing the
software ... my view is it should move into the area of the public domain,
legally protected for any use at that point, with all restrictions on use
rights completely removed, allowing binary deconstruction, reverse
engineering, machine code extraction, essentially use for any purpose.
 
It makes no sense that abandonware should not receive a legal standing,
such that any person or company who approaches it for use is actually
protected under the law. They should have that protection. The use of
that pre-existing tool should be at their disposal when the entity who
originally held rights to it walks away.
 
--
Rick C. Hodgin
mcheung63@gmail.com: Nov 30 06:36AM -0800

FUCK OFF ASSHOLE
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Nov 30 06:40AM -0800

> .. OFF ..
 
I love you, Mr. Cheung. I want the best for you. I want you to thrive.
I want you to have inner peace, love, and joy like you've never known.
 
I want you to be the full creation God intended for you before sin entered
in and destroyed everything.
 
I want to be your friend. I want to someone you can turn to for help,
and who I can turn to for help. I want us working together and being
like proper family members would be one to another, willing to help out
one another even to that extent.
 
I'm sorry you don't feel that way, Peter.
 
--
Rick C. Hodgin
woodbrian77@gmail.com: Nov 29 08:28PM -0800

On Tuesday, November 28, 2017 at 12:34:45 PM UTC-6, Öö Tiib wrote:
> 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.
 
 
If the team uses the :: prefix, then when a new person is
ready to have some of his code reviewed, if he hasn't already
figured it out from reading the code base, he should be told
to add the :: prefix. I see it as defensive programming.
 
 
Brian
Ebenezer Enterprises - In G-d we trust.
http://webEbenezer.net
David Brown <david.brown@hesbynett.no>: Nov 30 08:49AM +0100

> ready to have some of his code reviewed, if he hasn't already
> figured it out from reading the code base, he should be told
> to add the :: prefix.
 
Clearly the standard used by an existing team is important - consistency
in a style is higher priority than any particular decision about style
(unless that decision is truly idiotic).
 
But Öö said that using the identifier "std" for anything other than the
standard global namespace should be a firing offence - he did not say
that using "::std" should get you fired.
 
> I see it as defensive programming.
 
No, it is ugly paranoia. It is "defensive programming" in the same way
that putting copper bands over all the trees in your garden is
"defending against lightening strikes".
 
There are some kinds of coding where that level of "make sure everything
works, no matter what other people do" is justified. You can look in
some implementation library headers and see pervasive use of identifiers
like "__x" rather than "x". This is because it is legal in C and C++ to
have "#define x int" (or whatever) before including the header - and the
header should work no matter what the user does, as long as the
standards allow it. But that sort of thing makes the code messier and
harder to follow - it comes at a price, and it is only appropriate in
very specific circumstances.
 
Similarly, the use of "::std" might be justified within the standard
headers. In normal coding, it serves only to cause confusion (by being
different from almost all other C++ programmers) and make code messier.
 
I have only looked at the C++ headers for one compiler - gcc - but they
use "std" almost exclusively. There is only one use of "::std" that I
can see, and that looks like a mistake.
"Öö Tiib" <ootiib@hot.ee>: Nov 30 12:05AM -0800

> ready to have some of his code reviewed, if he hasn't already
> figured it out from reading the code base, he should be told
> to add the :: prefix. I see it as defensive programming.
 
Yes but what it is that your "defensive programming" defends against?
 
If you defend against name "std" really misused then you defend against
mythological thing. Who had real clown in their team who really named
something as "std" in their production C++ code-base? Why? When? Where?
What problems it caused? How it was resolved? I haven't seen or heard
about that during the very decades, no urban legends nor fiction, nothing.
 
If you defend against sabotage in general then you defend against
what sometimes happens and against that there are no defenses.
If programmer wants to disrupt C++ project or turn it into hard to
debug and maintain then they can do it in countless less palpable ways.
Risk of such enemy in your ranks can not be mitigated by "defensive
programming".
 
What are the most hard and annoying debugging problems? These are
when program only rarely does something incorrect. Gives wrong
results for unknown reasons. Nothing actually neither crashes nor
hangs because of that just results are wrong. Bonus points for being
disguised as typo in reasonable-looking code and being not reproducible
with same input data. Resulting program is untrustworthy and so useless.
That is what good antagonist would implement in your software and not
other namespace named "std".
 
I would buy if you said that "::std" is beautiful for your eyes
but as "defense" it is clearly pointless erosion of colon key.
"Öö Tiib" <ootiib@hot.ee>: Nov 30 01:49AM -0800

On Thursday, 30 November 2017 09:49:29 UTC+2, David Brown wrote:
 
> But Öö said that using the identifier "std" for anything other than the
> standard global namespace should be a firing offence - he did not say
> that using "::std" should get you fired.
 
Exactly. I see "::std" pointless. I still would write it if that was coding
standard. Consistency and "because we do it that way" are strong
reasons for me. Doing something slightly pointless is fine for
consistency and unity.
 
I argue against people who say that the "::std" helps against
actual, real problem. That is disinformation. They never provide
evidence. They even NEVER compose any fiction. How that
"problem" really did sting their or someone else's fanny? How
it took weeks to cure the swollen buttocks? Nada. Nil. Nothing.
So not worth to follow.
asetofsymbols@gmail.com: Nov 30 02:55AM -0800

I find that hide(nascondere) it is the main problem C++ has
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.

Wednesday, November 29, 2017

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

Christian Gollwitzer <auriocus@gmx.de>: Nov 29 07:40AM +0100

Am 28.11.17 um 08:25 schrieb Juha Nieminen:
> code harder to read. I have yet to see any of them giving a good
> argument why. They just don't like it... because they don't like
> it, period. No good reason.
 
It's partly a matter of taste, but for math functions I'd say that std::
is confusing. Compare:
 
(std::sin(q*r) + q*r*std::cos(q*r)) / std::exp(-q*std::pow(r,2))
(sin(q*r) + q*r*cos(qr)) / exp(-q*pow(r,2))
 
The second one is not only shorter, but closer to the formula as you
read it in textbooks and papers. And if you want to substitute the type,
e.g. for automatic differentiation, you need to drop th std:: because
the functions are overloaded outside of std::.
 
What is the correct way to do that? Include "math.h" instead of cmath?
using std::sin; using std::cos; ... ?
 
Actually, I'd love to have
 
using std::mathfunctions;
 
which import the basic trigonometric functions.
 
Christian
David Brown <david.brown@hesbynett.no>: Nov 29 09:19AM +0100

On 28/11/17 19:34, Öö Tiib wrote:
> 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.
 
As far as I can see, the standards put restrictions on the global
namespace "std" (or "::std") and namespaces nested within it, but not on
namespaces called "std" that are nested within other namespaces. The
(global) namespace "posix" is also reserved from use by user code.
Gareth Owen <gwowen@gmail.com>: Nov 29 07:30PM


> As Alf says, no one names a namespace `std`.
 
Well, I've been commissioned to write an app for a clap clinic
"Öö Tiib" <ootiib@hot.ee>: Nov 29 12:16PM -0800

On Wednesday, 29 November 2017 21:30:46 UTC+2, gwowen wrote:
> Ian Collins <ian-news@hotmail.com> writes:
 
> > As Alf says, no one names a namespace `std`.
 
> Well, I've been commissioned to write an app for a clap clinic
 
If you are one of those who religiously calls "sexually
transmitted infections" as STD and wants separate namespace
for those ... then perhaps write your app in Java. :p
legalize+jeeves@mail.xmission.com (Richard): Nov 29 10:48PM

[Please do not mail me a copy of your followup]
 
(Richard) legalize+jeeves@mail.xmission.com spake the secret code
>>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.
 
Maybe I misspoked there and you're supposed to do 'using std::swap;'
and not 'using namespace std;'.
--
"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>
"James R. Kuyper" <jameskuyper@verizon.net>: Nov 29 08:57AM -0500

On 11/29/2017 03:58 AM, Stefan Ram wrote:
> |values of the IEEE Standard ...
 
> BTW, did you guys know that ECMA-262 is a normative
> reference of ISO 14882?
 
What ECMA-262 has to say about it's Number type is relevant to C++ only
in the context of <regex>, the only place where ECMA-262 is mentioned
(and ECMA-262's Number type isn't mentioned directly anywhere).
 
IEC 559 (== ANSI/IEEE 754) is the relevant standard, and even then, only
if std::numeric_limits<T>::is_iec559 is true.
Christian Gollwitzer <auriocus@gmx.de>: Nov 29 10:03PM +0100

Am 28.11.17 um 17:42 schrieb Alf P. Steinbach:
> 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.
 
How "old" a compiler are you talking about? I've used a!=a for ages to
watch for NaN, and ordering the comparisons in a way that it does the
right thing with a NaN (i.e. a > 5 vs. ! (a <= 5) ).
 
Maybe if you use -ffast-math these things get optimized away, but I'm
not convinced that this buys you so much that it is worth. Without
-ffast-math you still have optimizations.
 
I've also seen that mostly NaN became a slow path of execution. When all
of the data became NaN, the whole computation slowed down by a factor of
2-3.
 
Christian
ram@zedat.fu-berlin.de (Stefan Ram): Nov 29 08:58AM

>and sets Nan with a mantissa corresponding to processing this
>string argument with a function strtod...
>I only have one question ... Why would this be necessary ???
 
ECMA-262 says it in all its glory:
 
|The Number type has exactly 18437736874454810627 (that is,
|2^64-2^53+3) values, representing the double-precision 64-bit
|format IEEE 754-2008 values as specified in the IEEE Standard
|for Binary Floating-Point Arithmetic, except that the
|9007199254740990 (that is, 2^53-2) distinct "Not-a-Number"
|values of the IEEE Standard ...
 
BTW, did you guys know that ECMA-262 is a normative
reference of ISO 14882?
David Brown <david.brown@hesbynett.no>: Nov 29 08:45AM +0100

On 28/11/17 17:57, James R. Kuyper wrote:
>> 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"?
 
Yes I did - sorry about that. I don't know why I mixed your names up
here (you both give good advice and good examples, so maybe I had just
read another post by Ben).
 
> actually compile and execute this code.
 
> In principle, a conceptually similar function could play a useful role
> in a compiler.
 
I could understand that - but I am fairly confident that Stefan is not
working on a compiler. Simply making a function as an alternative way
to express the rules seems reasonable - perhaps to help with Stefan's
teaching. However, if it is so hard to write the rules, I wonder if it
actually helps. I think Stefan is the only one who could tell us.
 
> 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.
 
Designing this sort of thing in a compiler is not going to be an easy task!
 
If /I/ were doing it, on a new compiler, I would try starting by
implementing the basics of the new "metaclass" proposal, using an extra
keyword "__class" instead of "class". "class" and "struct" can then be
implemented as metaclasses - and the rules for which methods are created
by the compiler, as well as a variety of warnings, can all be written in
C++ with metaclasses, rather than in the compiler itself.
 
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.

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.

Digest for comp.lang.c++@googlegroups.com - 25 updates in 9 topics

mirmikns@gmail.com: Nov 28 12:36AM -0800

Hello comrades.
 
I expected that std::nan is a constant (double) Nan, but it turns out that it is a function that takes a string argument and sets Nan with a mantissa corresponding to processing this string argument with a function strtod...
 
I only have one question ... Why would this be necessary ???
"James R. Kuyper" <jameskuyper@verizon.net>: Nov 28 11:22AM -0500

> Hello comrades.
 
> I expected that std::nan is a constant (double) Nan, but it turns out that it is a function that takes a string argument and sets Nan with a mantissa corresponding to processing this string argument with a function strtod...
 
> I only have one question ... Why would this be necessary ???
 
<https://en.wikipedia.org/wiki/IEEE_754#Formats>: "A NaN may carry a
payload that is intended for diagnostic information indicating the
source of the NaN." A NaN is represented by a biased-exponent field that
is filled with 1 bits, and a non-zero significand. The payload is stored
in the significand.
I'd cite IEEE 754 directly, if I could - but I don't have a copy of it.
I do have a copy of IEEE 854, which is a radix-independent variant of
IEEE 754, but I don't have it with me right now.
 
C++ does not mandate conformance with IEEE 754, but if
std::numeric_limits<T>::is_iec559 is true, then T conforms to IEC 559
(== ANSI/IEEE 754), and that is is overwhelmingly the most commonly
supported floating point standard. I think that some of the other
floating point standards may have a similar feature.
 
The specification for the strtod() function is incorporated by reference
from the C standard. Section 7.22.1.3p3 and p4 of the C standard specify
that a string starting with an optional sign followed by NAN will
produce a NAN, and that the "NAN" may optionally followed by sequence of
digits and nondigits - which sequences are allowed and what they mean is
implementation-defined (you might expect that everything is either a
digit or a non-digit, but that's not how those terms are defined. The
character '_', the roman letters 'a' through 'z' and 'A' through 'Z',
and any UCN are guaranteed to qualify as nondigits. Any other characters
that qualify as nondigits are implementation-defined - C standard
6.4.2.1p1).
 
The description of the iostreams library does not describe the handling
of NANs directly - it describes the relevant functions as equivalent to
calls to members of the printf() family of functions. The definitions of
those functions are incorporated by reference from the C standard.
Section 7.21.6.1p8 of the C standard specifies that if you print a NaN,
the output will start with an optional '-' followed by "nan" (if you use
%f, %e, %g, or %a) or "NAN" (if you use %F, %E, %G, or %A) optionally
followed by an implementation-defined sequence of characters.
 
Both ends of this process are entirely implementation-defined, which
allows an implementation to make full use of IEEE 754 NaNs with
payloads, or not, at the implementor's discretion. I would expect most
implementations which support NaN payloads to define the character
string produced by printf() of a NaN to match the string passed to
strtod() to create that NaN.
 
Thus, code which creates a NaN using strtod() can encode a limited
amount of information about the context in which it was created, which
can be decoded by printing the NaN.
ram@zedat.fu-berlin.de (Stefan Ram): Nov 28 06:03AM

>exactly the result that I expect, based upon the assumption that ::std::
>IS necessary, at least in some circumstances. Have I misunderstood
 
There is a conceptual difference:
 
::std::xyz
 
means:
 
"The name »xyz« from /the/ famous global std namespace."
 
, while
 
std::xyz
 
means:
 
"The name "xyz" from /any/ namespace "std" that happens
to in the scope of the usage of this expression".
 
Maybe the second possibility is a good thing sometimes,
when one wants to assign custom meanings to std::-names?
 
~~
 
WRT
 
using namespace ::std;
 
: even Bjarne Stroustrup uses it in his books. So it should
be accepted for tutorial examples or small or short-lived
programs. (I still do not use it in my own tutorial.)
 
~~
 
Pastability
 
A snippet like
 
::std::cout << 22 << '\n';
 
can be copied to every place:
 
- No need to verify that there is a
»using namespace ::std;« at the beginning
 
- No need to verify that there is no
(and will never be) another namespace
"std" in the vicinity.
 
A snippet like »cout << 22 << '\n'« would be more "fragile".
ram@zedat.fu-berlin.de (Stefan Ram): Nov 28 06:19AM

>similar issues would apply to the other four things that you want
>calculated, though I haven't bothered checking yet.
>Does this even remotely resemble what you're looking for?
 
I was starting to write about constructors for my
German-language C++ course.
 
Of course, I wanted to state the conditions under
which constructors are declared implicitly.
 
The rules seemed to be complicated. But maybe they
just /seemed/ to be complicated /to me/, but were
really quite simple for an expert who might be able
to give all the rules in just a few lines of text?
 
So, I had the idea to ask in this newsgroup.
 
But then I also thought that the English language
might add some ambiguity or vagueness to rules, and
that ambiguity or vagueness could be avoided by
expressing the rules in a more formal manner.
 
Since we already got C++ as a formal language,
it would be natural to express the rules using C++
herself.
 
From the rest of your reply I take it that the rules
are so complicated that even for an expert it is
not simple to write such a function.
 
Moreover, the rules might change in the future:
Scott Meyers wrote in 2014:
 
"At some point, analogous rules may be extended to the
copy operations, because C++11 deprecates the automatic
generation of copy operations for classes declaring copy
operations or a destructor."
 
Another complication is that in that point of my course, I
do not have explained all other parts of the language and
- wishing to avoid forward references - I still have to
exclude mentioning some parts of the language.
 
So, in the final end, it might come down to me having to use
some simplifications in that part of my course and only
mention some common situations in which certain special
member functions are generated or are not generated.
ram@zedat.fu-berlin.de (Stefan Ram): Nov 28 12:18PM

The Web page
 
en.cppreference.com/w/cpp/language/eval_order
 
says:
 
»In a shift operator expression E1<<E2 and E1>>E2, every
value computation and side-effect of E1 is sequenced
before every value computation and side effect of E2«.
 
A recent draft indeed says:
 
»The expression E1 is sequenced before the expression E2.«
 
in 8.8p4 (Shift operators).
 
. So is this defined now:
 
cout << ++i << i++;
 
? Here, an older gcc with -std=c++17 gives:
 
main.cpp
 
#include <iostream>
#include <ostream>
 
int main()
{ int i = 1;
::std::cout << i++ << ++i << '\n'; }
 
transcript
 
23
 
So, a real C++ compiler would print:
 
13
 
?
ram@zedat.fu-berlin.de (Stefan Ram): Nov 28 04:11PM

>Overloaded operators follow the rules for function calls. For example,
>if you overload operator&& it will not short-circuit even though the
>built-in one does.
 
I find in a recent draft a section
 
16.3.1.2 Operators in expressions [over.match.oper]
 
which says in p2:
 
|If either operand has a type that is a class or an
|enumeration, a user-defined operator function might be
|declared that implements this operator
 
...
 
|the operands are sequenced in the
|order prescribed for the built-in operator
 
.
Bo Persson <bop@gmb.dk>: Nov 28 03:46PM +0100

On 2017-11-28 13:18, Stefan Ram wrote:
 
> So, a real C++ compiler would print:
 
> 13
 
> ?
 
No. The rule is for the built in shift operator.
 
Overloaded operators follow the rules for function calls. For example,
if you overload operator&& it will not short-circuit even though the
built-in one does.
 
 
Bo Persson
Andrey Karpov <karpov2007@gmail.com>: Nov 28 05:43AM -0800

Today's article is somewhat unusual, if only because instead of reviewing one project, we'll be comparing three projects at once, looking for the one with the most interesting bugs and - which is of particular interest - the one with the highest code quality. The projects we are going to review are Firebird, MySQL, and PostgreSQL. So let's get started: https://www.viva64.com/en/b/0542/
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Nov 28 05:57AM -0800

On Tuesday, November 28, 2017 at 8:44:04 AM UTC-5, Andrey Karpov wrote:
> Today's article .. we'll be comparing three projects at once...
 
How is this useful information? Bugs are bugs. Why would I care how
bugs in app1 relate to app2 or app3? This seems like info sanitizer
and compiler author developers would want to know so they could flag
them at compile time so that common types of coding patterns are identified
and reported on. It would be interesting for a software security overview,
but without context, without a personal impact ... how is it meaningful?
 
--
Rick C. Hodgin
Manfred <noname@invalid.add>: Nov 28 02:43PM +0100

On 11/27/2017 8:20 AM, Alf P. Steinbach wrote:
 
> Explicitly writing out the iterator type can be verbose and brittle, and
> so I wouldn't do that, but the question of how to communicate the
> constness of the iterator's referent is interesting.
 
[snip]
 
>         assert_is_const( *it );
>         //...
>     }
 
For this original problem, an even simpler writing would directly use
cbegin() and cend().
 
[snip]
 
 
> Much of the point is that one really doesn't care about the exact type
> of an iterator, and that it's desirable to /not/ know, because using
> that knowledge just makes the code brittle and possibly non-portable.
 
Indeed.
Christopher Pisz <christopherpisz@gmail.com>: Nov 27 04:31PM -0800

Everyone is quick to point out the "Rule of Zero" in code reviews, peer conversations, and Stack Overflow comments/answers.
 
I am not a believer. I'd like to be. Usually if enough people agree on something enough for it to get its own label and become an idiom, then it is well thought out....
 
So, let me explain my reason for not believing:
 
I cannot count the number of times I have been tasked to debug a crash dump from a production crash. While debugging said dump, I can look up and down the call stack and sometimes I have the need to see "When is this class being constructed?" Secondarily, I might need to see "What is its or its members addresses when it is?" This usually leads to some other place in the code after evidence that more instances are being created than should be, or when addresses or sizes are not what is expected.
 
This could also apply, when I want to see "When is this class being assigned to?"
 
As such, I've always implement all 5 methods, trivial or not, in order to provide a place to break in future debug sessions while reproducing the conditions in the dump without having to change the source. Without them, there would be no way (easily) to perform the above debugging session.
 
If you modify source in order to provide a line of code to break on, your crash dump is no longer usable with the source.
 
Now, some would say that this situation does not arise often enough for them to add more code, and more potential bugs, in the case of trivial constructors and assignment operators. However, I'd argue that one occasion having to explain to your superiors that you have to make another build, redeploy to production, reproduce the crash, and retrieve another dump, in order to even start debugging the problem, is enough to change one's outlook. That is not an enjoyable experience and it has occurred to me a number of times.
 
So, please make me a believer!
 
Tell me how I can accomplish the above described debugging session given a crash dump, when there is no line available to break on, after being a good boy and following the "Rule of Zero".
 
Namely:
 
1) Break any time any instance of a given class is being constructed without any lines of constructor code to break on.
 
2) Break any time any instance of a given class is being assigned to without any lines of assignment operator to break on.
 
I am using Visual Studio, and more specifically Visual Studio 2015. I've heard people in *nix actually have a means to accomplish the task without lines to break on. I've never had the pleasure of being in that environment though. I'd think that even if it is only a problem for Windows users, that is still a good enough number of people to raise the discussion.
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Nov 28 04:44AM +0100

On 11/28/2017 1:31 AM, Christopher Pisz wrote:
> in that environment though. I'd think that even if it is only a
> problem for Windows users, that is still a good enough number of
> people to raise the discussion.
 
Not addressing your problem but: it's more acute for basic types.
 
I once replaced a basic type with a full class type wrapper, for some
chosen variables, just for that kind of debugging. It wasn't my project.
These guys (re-) initialized their global variables from rather
inconceivable places at unpredictable times.
 
The order to not waste time on cleaning up the code was very firm. I
learned belatedly that it included not fixing bugs that prevented the
new code from functioning (that doesn't make sense, but not much did: my
theory is they were so incompetent as to be effectively insane). Half a
year later or so, questions about "what is this construction /for/"
appeared in this group, and I knew enough to answer them.
 
 
Cheers!,
 
- Alf
"Öö Tiib" <ootiib@hot.ee>: Nov 28 01:54AM -0800

On Tuesday, 28 November 2017 02:31:12 UTC+2, Christopher Pisz wrote:
 
<snipping to point>
 
> So, please make me a believer!
 
I use rule of zero as quite strong rule and can help to administer
it, but beware, my worldview is not a cult. It does not work on
belief. C++ is full of traps. Period. It is workable with awareness
understanding and on pile of tricks. If some "silver bullet" seems
to work always then it is actually superstition. You will be trapped
and then we all cheer "Gotcha!!". ;)
 
> without any lines of constructor code to break on.
 
> 2) Break any time any instance of a given class is being assigned to
> without any lines of assignment operator to break on.
 
Yes, our debuggers typically have no feature to break and to step
in implicitly generated code. When we only want to break or to trace
from the 5 then it is not too tricky to simplify it by typical separation
of concerns.
 
For example we can add a special member (or base) to our class with
all 5 members explicitly implemented. Implicitly-generated 5 are
required to call the 5 of such base or member and so we can break
in (or trace from) such stock class (or more likely template) instead
of implementing the 5 in every containing class.
 
That is already useful but we can further extend it with flexibility
features like:
1) to turn the fact of presence of such member on and off compile-time
2) to inject some other "indicating operations" besides trace into it
3) to select if it does its operation and from what members on and
off run-time
... and so on ...
 
As result instrumentation code can be left in forever and so can
be useful in unit-tests as well. Hopefully you see how to implement
such thing is lot more interesting and beneficial than to tediously
and error-pronely implement the 5 for each and every class.
James Kuyper <jameskuyper@verizon.net>: Nov 27 10:53PM -0500

> "::std::" prefix is unnecessary but "std::" isn't as "using namespace std;" is egregious.
 
I've heard that claim before, but I admit to being confused by it. The
following code compiles without warning or error messages and produces
exactly the result that I expect, based upon the assumption that ::std::
IS necessary, at least in some circumstances. Have I misunderstood
something?
 
 
#include <cstdio>
namespace kuyper {
namespace std {
void printf(const char *) { return;}
 
}
void func(void)
{
std::printf("Fake printf\n");
::std::printf("Real printf\n");
}
}
 
int main(void)
{
kuyper::func();
return 0;
}
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Nov 28 06:40AM +0100

On 11/28/2017 4:53 AM, James Kuyper wrote:
> kuyper::func();
> return 0;
> }
 
No-one names a namespace `std`.
 
But that doesn't mean that Leigh is right about `using namespace std;`
always being ungood. That's like thinking pointers are always ungood,
say. To build a skyscraper in the same way as a small toy dollhouse,
just to be able to follow a simple set of mechanical rules for tool usage.
 
The way I look at code is more like overall structure first, and then
the details attach into slots of that structure here and there, for
whatever I look closer at. Some programmers say that verbosity with
everything qualified everywhere brings clarity, but that doesn't work
for me: it's just distracting redundancy. I guess they're focused on one
very tiny piece of code at a time, and then find it problematic to deal
with an unqualified `distance`, say, which, with a sufficiently narrowed
view just could be `std::distance`, or something else.
 
Cheers!,
 
- Alf
Juha Nieminen <nospam@thanks.invalid>: Nov 28 07:19AM

> exactly the result that I expect, based upon the assumption that ::std::
> IS necessary, at least in some circumstances. Have I misunderstood
> something?
 
Does the standard allow using the name 'std' for a namespace other
than the standard one? (I honestly don't know.)
Juha Nieminen <nospam@thanks.invalid>: Nov 28 07:25AM


> : even Bjarne Stroustrup uses it in his books. So it should
> be accepted for tutorial examples or small or short-lived
> programs. (I still do not use it in my own tutorial.)
 
The irony is that with very small snippets of code, using that
line often makes the code *longer*, not shorter.
 
Also, it doesn't increase readability. It only decreases it.
 
For some reason I can't really comprehend, many people have this
obstinate notion that using the "std::" previx somehow makes the
code harder to read. I have yet to see any of them giving a good
argument why. They just don't like it... because they don't like
it, period. No good reason.
 
In actuality the "std::" prefix works as a visual hint that
"a standard library name is being used here". It's a bit like
code coloring. It helps recognize standard library names with
a quick visual scan. Also, with names you don't recognize it
immediately tells you that it's a name from the standard library,
not some user-declared name somewhere else.
 
One some guy tried to prove that the "std::" prefix makes the
code unreadable and ugly by concocting a short piece of code
with something like ten uses of a standard library name.
Ironically, the version with the "std::" prefixes was actually
easier to understand than the one without them.
Ian Collins <ian-news@hotmail.com>: Nov 28 08:59PM +1300

On 11/28/2017 07:03 PM, Stefan Ram wrote:
> to in the scope of the usage of this expression".
 
> Maybe the second possibility is a good thing sometimes,
> when one wants to assign custom meanings to std::-names?
 
As Alf says, no one names a namespace `std`.
 
--
Ian.
David Brown <david.brown@hesbynett.no>: Nov 28 09:39AM +0100

On 28/11/17 07:03, Stefan Ram wrote:
 
> means:
 
> "The name "xyz" from /any/ namespace "std" that happens
> to in the scope of the usage of this expression".
 
Surely every C++ programmer knows not to make their own namespaces
called "std" ? There is no value in uglifying all your code to help
with a problem that does not exist.
 
 
> Maybe the second possibility is a good thing sometimes,
> when one wants to assign custom meanings to std::-names?
 
There are times when you want to overload std:: names, such as
std::swap. And then you want to be sure that you get that overload
/every/ time.
 
 
> : even Bjarne Stroustrup uses it in his books. So it should
> be accepted for tutorial examples or small or short-lived
> programs. (I still do not use it in my own tutorial.)
 
Code snippets in books are not examples of good real-world code. They
are to show a particular feature under discussion at the time.
 
 
> can be copied to every place:
 
> - No need to verify that there is a
> »using namespace ::std;« at the beginning
 
Yes, and "std::cout" can be pasted without verifying that "using
namespace std;" is in action.
 
No one argues against having the "std::" namespace prefix (sometimes you
want it, sometimes you want a "using"). But almost everyone disagrees
with your use of "::std::" instead of the normal "std::".
 
 
> - No need to verify that there is no
> (and will never be) another namespace
> "std" in the vicinity.
 
Have you ever seen any code that has its own "std" namespace with its
own identifiers, making "::std::" necessary?
 
David Brown <david.brown@hesbynett.no>: Nov 28 09:47AM +0100

On 28/11/17 08:19, Juha Nieminen wrote:
>> something?
 
> Does the standard allow using the name 'std' for a namespace other
> than the standard one? (I honestly don't know.)
 
I found this in the C++14 standard:
 
17.6.4.2.1
1
Overview
[constraints]
Namespace std
[namespace.std]
C++
The behavior of a
program is undefined if it adds declarations or definitions to namespace
std or to a
namespace within namespace std unless otherwise specified. A program may
add a template specialization
for any standard library template to namespace std only if the
declaration depends on a user-defined type
and the specialization meets the standard library requirements for the
original template and is not explicitly
prohibited.
 
 
I also had a quick look at some C++ standard library headers (from a gcc
installation). They are full of "std::", with the occasional
function-local using clause like "using std::swap;". Only once, in the
whole directory of include files, did I find "::std::" - it occurs in
"functional" and does not appear to be used intentionally.
 
So on at least one major C++ compiler, the whole standard library could
break if someone has been messing with "std" namespaces in such a way
that "::std::" will work but "std::" will not.
"James R. Kuyper" <jameskuyper@verizon.net>: Nov 27 10:40PM -0500

On 11/24/2017 06:49 AM, Stefan Ram wrote:
> MA = /* as above, but for the move assignment */
> DS = /* as above, but for the destructor */
 
> return make_tuple( DC, CC, CA, MC, MA, DS ); }
 
I'll handle the first one, DC, to give you an idea of what's actually
involved. I'm basing this off of C++2011.
 
auto explain
( bool DCu /* whether a default constructor is user-provided */,
bool Cu /* whether any constructor is user-provided */,
bool UVntdc /* Whether it is a union-like class that has a variant
member with a non-trivial default ctor. */,
bool NSDMNIR /* Whether any non-static data member with no
brace-or-equal_initializer is of reference type. */,
bool NVNSDMCQNBDc /* Whether all non-variant non-static data members
of const-qualified type (or array thereof) which have no
brace-or-equal-initializer have default constructors. */,
bool UVMCQ /* Whether it is a union and all members are of
const-qualified type (or array thereof) */,
bool NUMCQ /* Whether it is a non-union class and all members of any
anonymous union member have const-qualified type (or array
thereof) */,
bool BCNSDMNBDc /* Whether all direct or virtual base classes and
non-static data members with no brace-or-equal-initializer have
either a a default constructor, or an applicable overload that is
unambiguous and neither deleted nor inaccessible. */,
...
{
DC = /* 1 when a default constructor will be
implicitly-declared (or
 
2 if this happens, but is deprecated) or
 
0 when it will /not/ be implicitly-declared
(or implicitly-declared as deleted) under the
conditions described by the parameter values */
!Cu && // Implicitly declare (12.1p4)
// and not implicitly declared as having been deleted.
!(UVntdc || NSDMNIR || !NVNSDMCQNBDc || UVMCQ || NUMCQ
!BCNSDMNBDc);
 
I had to add seven arguments to your function, while making no use of
the only argument you probably thought was relevant. I expect that
similar issues would apply to the other four things that you want
calculated, though I haven't bothered checking yet.
 
Does this even remotely resemble what you're looking for?
 
It's entirely possible that one or more of the arguments I added is
described or used in exactly the opposite way that it should be - this
is the kind of question where that kind of mistake is easy to make.
However, I hope it's clear what the general framework of this expression
should look like.
David Brown <david.brown@hesbynett.no>: Nov 28 09:24AM +0100

On 28/11/17 07:19, Stefan Ram wrote:
> some simplifications in that part of my course and only
> mention some common situations in which certain special
> member functions are generated or are not generated.
 
I would have thought you'd be looking at type traits here. There are
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,
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. But I think you
want to start with the existing type traits. Then move on to
constructing your own type traits for anything missing. For things that
you can't figure out this way, you then want to ask if it really is a
useful feature.
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Nov 28 04:43AM +0100

On 11/27/2017 5:03 PM, Öö Tiib wrote:
 
> Does anyone know why move constructor and move assignment are implicitly
> noexcept(false)? By default (e.g. = default) these are also noexcept(true)
> when possible like the destructor is.
 
Today move semantics is a bit more, but originally it was an
optimization of copying.
 
As I recall, for that purpose some felt it was important that move
operations could be generated automatically by the compiler, wholly or
partially in terms of old possibly-throwing copy operations.
 
With such partially copy-based move operations, one hoped to get
significant speedups for legacy code just by recompiling, and over time
more of that the more old pure copy semantics in such code was
complemented with user defined move operations.
 
Regardless of whether my recollection of the rationale is correct,
having possibly throwing move operations was considered sufficiently
important to introduce a possible UB in std::vector reallocation, and to
generally just complicate things.
 
I think that decision was wrong: let's design this car partially as a
tractor so that it will work in some fashion also out in the fields, not
just on the road. Huh? What?
 
My 2c.
 
 
Cheers!,
 
- Alf
"Öö Tiib" <ootiib@hot.ee>: Nov 27 10:12PM -0800

On Monday, 27 November 2017 18:40:32 UTC+2, Daniel wrote:
> > I can hardly imagine any reasons to throw from ... move constructor
> > or move assignment.
 
> One reason, if move must replace an allocator, and propagate_on_container_move_assignment::value is false, the implementation may want to perform a copy, then copy can throw.
 
Thanks. Yes, C++17 made move assignments of the containers
that have allocator with 'propagate_on_container_move_assignment'
or 'is_always_equal' trait noexcept(true). That means 99.9% of
containers. Before C++17 all the move assignments of all containers
were noexcept(false).
 
We technically talk about unusual container whose owned resources
can not be transferred because of its odd allocator.
Why not to make such container simply not move-assignable?
"Öö Tiib" <ootiib@hot.ee>: Nov 27 11:45PM -0800

On Tuesday, 28 November 2017 05:43:40 UTC+2, Alf P. Steinbach wrote:
> significant speedups for legacy code just by recompiling, and over time
> more of that the more old pure copy semantics in such code was
> complemented with user defined move operations.
 
I have had same impression. The programmers do not typically care if
the underlying resources of throw-away objects are transferred or copied.
It is quite inconvenient to make some higher level logic dependent on
such low level details so it was quite bad legacy hack that did break
because of recompiling with C++11.

However we must care if something can throw exceptions or cannot and
(if possible) even what these exceptions are. ;)
 
> having possibly throwing move operations was considered sufficiently
> important to introduce a possible UB in std::vector reallocation, and to
> generally just complicate things.
 
Most robust would be to demand that move constructors and move assignments
simply may not throw. If author can't ensure that then '= delete' it and
done. The cloud of complications (like 'std::is_nothrow_move_assignable')
that no novice will ever learn to use correctly would vanish.
 
> I think that decision was wrong: let's design this car partially as a
> tractor so that it will work in some fashion also out in the fields, not
> just on the road. Huh? What?
 
Yes, and if they wanted actually ATV then why they did mount both the
spoiler and the snowplough to it? However I was not even dreaming of
anything charming. I was merely wondering why the move operations are
implicitly so inconveniently noexcept(false) while it is rather unusual
that these throw.
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.