Monday, February 24, 2020

Digest for comp.lang.c++@googlegroups.com - 22 updates in 6 topics

legalize+jeeves@mail.xmission.com (Richard): Feb 24 06:08AM

[Please do not mail me a copy of your followup]
 
Lynn McGuire <lynnmcguire5@gmail.com> spake the secret code
 
>"2020-02 Prague ISO C++ Committee Trip Report — 🎉 C++20 is Done! 🎉"
 
>https://www.reddit.com/r/cpp/comments/f47x4o/202002_prague_iso_c_committee_trip_report_c20_is/
 
>Wow, that is a lot of new stuff that I probably will not use.
 
Based on your comments in the past, this is what I expect you will
use (but maybe only indirectly):
 
- modules: who doesn't want a faster build?
- concepts: if only as a user of the standard library, for better
template error messages
- ranges: aren't you tired of typing c.begin(), c.end() as
arguments all the time?
- constexpr: really handy for writing code evaluated at compile
time instead of wacky template metaprogramming
- std::format: everyone complains about the speed and usability of
stream formatting
- operator<=>: makes it easier to write comparable types
- std::span: type safe C-style arrays
- std::source_location: one more nail in the preprocessor coffin
 
That's pretty much most of the features on that list. What do you
expect you wouldn't actually use from the above list?
--
"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>
legalize+jeeves@mail.xmission.com (Richard): Feb 24 06:10AM

[Please do not mail me a copy of your followup]
 
Daniel <danielaparker@gmail.com> spake the secret code
>> coroutines are definitely not minor. Arguably ranges aren't either.
 
>Yes, but to what end? Open sources libraries like rust serde or java jackson
>aren't even possible in C++, because C++ doesn't have the types.
 
It would help if you provided specific examples because I doubt
most people here are familiar with those libraries.
--
"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>
Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo>: Feb 24 01:22AM -0500

Chris Vine wrote:
> type char[] (the type which most aligned uninitialized storage will end
> up being) you have to use std::launder to access objects in the buffer
> through the buffer pointer.
I think this is unnecessary unless the new object's
 
"
complete object is a const object or it is a base class subobject
"
 
(see 17.6.4-5) so most code should stay valid (or invalid -- see the discussion
on "Union type punning in C++ redux" thread).
Juha Nieminen <nospam@thanks.invalid>: Feb 24 07:50AM

>> Both C++14 and C++17 were relatively minor updates.
 
> C++14 and C++17 may have been minor updates, but concepts, modules and
> coroutines are definitely not minor. Arguably ranges aren't either.
 
I don't understand your point.
 
Or perhaps, it's you who didn't understand my point. I was responding to
"what happened to Stroustrup's request to slow down the development?"
with "it has already been 9 years with almost nothing happening,
how much slower than that does it need to be (if this C++20 is
"too fast")?"
Juha Nieminen <nospam@thanks.invalid>: Feb 24 07:51AM

> Wow, that is a lot of new stuff that I probably will not use.
 
I'm quite certain that many people said exactly that in 2011, and who are
now using quite many C++11 features.
Jorgen Grahn <grahn+nntp@snipabacken.se>: Feb 24 08:20AM

On Sun, 2020-02-23, Juha Nieminen wrote:
 
> How much more slow does it need to be? If no major updates are
> done in 9 years, and that's *still* too fast, then what is the
> proper timescale in that case? 20 years? 50 years? What?
 
You may have misunderstood me: I didn't ask for a slowdown;
I literally wondered what effect Stroustrup's complaints had.
 
/Jorgen
 
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Feb 24 10:53AM

On Mon, 24 Feb 2020 01:22:22 -0500
> Chris Vine wrote:
[snip]
> "
 
> (see 17.6.4-5) so most code should stay valid (or invalid -- see the
> discussion on "Union type punning in C++ redux" thread).
 
I doubt you are right. The point is that a char[] (or std::byte[])
buffer is not a "a pointer that pointed to the original object" within
the meaning of §6.8/8 of C++17. At any rate, that is the view of the
authors of cppreference.com, who are usually pretty good. They say
(https://en.cppreference.com/w/cpp/utility/launder) that a typical use
for std::launder is "Obtaining a pointer to an object created by placement
new from a pointer to an object providing storage for that object", and
they give this example:
 
struct Y {int z;};
 
alignas(Y) std::byte s[sizeof(Y)];
Y* q = new(&s) Y{2};
const int f = reinterpret_cast<Y*>(&s)->z; // Class member access is undefined behavior:
// reinterpret_cast<Y*>(&s) has value "pointer to s"
// and does not point to a Y object
const int g = q->z; // OK
const int h = std::launder(reinterpret_cast<Y*>(&s))->z; // OK
 
The aforementioned code would have been valid in C++98/11/14 in my view.
The new lifetime rules in question seem intended to sanction compiler
optimization as a supplement to the aliasing rules (which are not broken
by the code above), and std::launder forms an optimization barrier for
those cases where this optimization would produce the wrong result.
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Feb 24 11:15AM

On Mon, 24 Feb 2020 10:53:33 +0000
> The aforementioned code would have been valid in C++98/11/14 in my
> view.
 
And indeed I see that Stroustrup constructs a similar buffer to
illustrate the alignas declaration at section 6.2.9 of his "The C++
Programming Language", 4th Edition. (He uses std::unitialized_copy()
to put items in the buffer, which is a wrapper for placement new.)
Daniel <danielaparker@gmail.com>: Feb 24 05:19AM -0800

On Monday, February 24, 2020 at 6:15:15 AM UTC-5, Chris Vine wrote:
 
> And indeed I see that Stroustrup constructs a similar buffer to
> illustrate the alignas declaration at section 6.2.9 of his "The C++
> Programming Language", 4th Edition.
 
boost now uses
 
template <class T, class U>
T launder_cast(U* u)
{
#if defined(__cpp_lib_launder) && __cpp_lib_launder >= 201606
return std::launder(reinterpret_cast<T>(u));
#elif defined(BOOST_GCC) && BOOST_GCC_VERSION > 80000
return __builtin_launder(reinterpret_cast<T>(u));
#else
return reinterpret_cast<T>(u);

No comments: