Wednesday, December 13, 2017

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

Ian Collins <ian-news@hotmail.com>: Dec 09 12:43PM +1300

On 12/09/2017 10:16 AM, jacobnavia wrote:
> }
> };
 
> in C++ 2017.
 
The example here: https://www.viva64.com/en/b/0533/#ID0EELAK
 
presents, in my opinion, a more practical example if day to day code.
 
template <typename T>
auto GetValue(T t)
{
if constexpr (std::is_pointer<T>::value)
{
return *t;
}
else
{
return t;
}
}
 
I have had to use convoluted SFINAE style code to get a similar effect.
I'll be updating that code next time I visit it.
 
constexpr if is one of apparently innocuous changes that will prove very
useful once you hit a situation where it saves code - especially where
it moves code from run to compile time.
 
--
Ian.
scott@slp53.sl.home (Scott Lurndal): Dec 08 05:08PM


>Does someone has anything to say about the /actual/ C++17? What
>features will I use the most when I get around to upgrading, in a few
>years?
 
It will likely be a decade before our toolchain and dependencies
will support moving to a version of GCC that supports C++17.
legalize+jeeves@mail.xmission.com (Richard): Dec 08 06:59PM

[Please do not mail me a copy of your followup]
 
Ian Collins <ian-news@hotmail.com> spake the secret code
>> will support moving to a version of GCC that supports C++17.
 
>Why so long? I would have though any changes that improve performance
>would be welcomed in your line of work.
 
Chandler Carruth had a good talk at pacific++ recently on this topic:
<https://www.youtube.com/watch?v=uZI_Qla4pNA>
 
When I worked at Fusion-io, we targeted enterprise Linux distributions
(RHEL, SLES, etc.) where the default toolchain on the platform lagged
considerably.
 
At another employer, we were stuck using older tools due to ABI/OS
compatibility concerns. (The application had a plugin architecture
and binary compatibility was susceptible to breakage by changing
toolchains.)
 
Chandler's point was that for many people it is feasible to build
clang yourself in order to obtain an up-to-date toolchain. On the
Windows side, VS2017 claims ABI compatibility with VS2015, so that
shouldn't be too much of a problem.
--
"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>
red floyd <dont.bother@its.invalid>: Dec 08 09:28AM -0800

On 12/8/2017 12:46 AM, David Brown wrote:
> of inches, hundreds of dead post-it notes, three keyboards, coffee cups,
> electronics boards, uncountably many USB sticks. I like to have things
> at hand!
 
Quit snooping around my office!!!
Intelli2 <intelli2@mama.com>: Dec 08 04:54PM -0500

Hello....
 
 
I know about Bill Gates, and how he thinks..
 
Here is my way to be a winner..
 
You have to think like a manager that thinks big money and you have thus
to integrate new interesting inventions into your products, like
integrating scalable algorithms and such and there implementations into
your Embarcadero or Microsoft products, that better your name and that
brings much more customers and that brings investors, thus that brings
big money, this is my way of thinking, and i think that Bill Gates has
followed my way of thinking and is in accordance with my way of thinking.
 
Thank you,
Amine Moulay Ramdane.
ram@zedat.fu-berlin.de (Stefan Ram): Dec 08 01:40PM

>That said, since 2012 I did not participate in the active moderation,
>because I got too ill
 
I wish you all the best for your future health and that the
illness may never come back or at least get less severe, so
that you may continue to work on your projects for a very
long time!
 
>The moderation policy recommends max 70 columns in a source code line,
>giving some leeway for quoting.
 
I think some indentations were modified even when lines were
short. I append a quotation of a message that I have
submitted to comp.lang.c++.moderated on Oct 23 of 2009, and
with which I wanted to check the appearence of indented
text. IIRC it was not published in the newsgroup, or at
least the problem was not addressed further. (The rest of
this here 2017 post only consists of that 2009 post.
The Date header is missing, because it was not stored for
technical reasons. Some headers were removed from the post
for simplification.)
 
Newsgroups: comp.lang.c++.moderated
Subject: Re: Pronunciation of locale and facet
References: <b62de145-ee8d-4aaf-aac7-fdf73667baf1@u36g2000prn.googlegroups.com>
From: ram@zedat.fu-berlin.de (Stefan Ram)
Content-Transfer-Encoding: 8bit
Content-Language: en
Message-ID: <pronunciation-20091023194229@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
 
Mr360 <mister_360@yahoo.com> writes:
>What is the (proper? accepted? typical? American-vs-British?)
>pronounciation of locale and facet?
 
[lo 'k=3DC3=3DA6l]
['f=3DC3=3DA6s =3DC9=3DAAt]
 
I hope the moderation software can transfer
 
Content-Type: text/plain; charset=3DUTF-8
Content-Transfer-Encoding: quoted-printable
 
.
 
~~
 
This test intends to see whether the moderation
process modifies the indentation of paragraphs.
This paragraph was not indented when I sent the
post.
 
This test intends to see whether the moderation
process modifies the indentation of paragraphs.
This paragraph was indented by 1 space when I
sent the post.
 
This test intends to see whether the moderation
process modifies the indentation of paragraphs.
This paragraph was indented by 2 spaces when I
sent the post.
 
This test intends to see whether the moderation
process modifies the indentation of paragraphs.
This paragraph was indented by 3 spaces when I
sent the post.
 
This test intends to see whether the moderation
process modifies the indentation of paragraphs.
This paragraph was indented by 4 spaces when I
sent the post.
ram@zedat.fu-berlin.de (Stefan Ram): Dec 08 10:57AM

>A typical sign of noise ahead, in the context of the purely technical
>postings that were the norm in clc++m, is that a posting is peppered
>with the word "you"; then it might be heading in a personal direction.
 
The moderation of one such group (clc++m or clcm) changed
the contents of my posts, by changing the indentation from
2 to 3 in some cases. The moderation did not allow a post to
demonstrate and discuss this in the moderated group.
 
One really should not publish something that someone did /not/
wrote (like code with an indentation of 3) under his name.
legalize+jeeves@mail.xmission.com (Richard): Dec 08 10:29PM

[Please do not mail me a copy of your followup]
 
The poster boy use case for constexpr if is selection between algorithms
at compile-time. (It is the 3rd example on given on that web page; I
would have made it the first example.)
 
constexpr if is syntactic sugar that makes code easier to read,
easier to understand and easier to maintain. You could do the same
thing in C++98 because the fundamental enabling feature for compile-time
algorithm selection is the template mechanism along with specialization.
 
You can keep doing C++98 style compile-time algorithm selection if you
want; it worked before and will still work.
 
However, your code will be much easier to read, write and maintain with
constexpr if.
 
It is very much like lambdas. You could have written you own functor
classes before, but it was tedious and required lots of boiler plate.
This resulted in people duplicating effort of standard algorithms
because writing the functor was tedious. Lambdas give you the
syntactic sugar that makes using standard algorithms more straight
forward.
 
You would think that anything making C++ easier to read, write and
maintain would be welcome, but I guess some people insist on seeing
sour grapes in everything.
--
"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>
jacobnavia <jacob@jacob.remcomp.fr>: Dec 08 10:16PM +0100

Is this really needed?
 
Look, constexpr if, at
https://medium.com/@LoopPerfect/c-17-vs-c-14-if-constexpr-b518982bb1e2
 
That piece explain us why this improvement to C++ is necessary. You have
code like this in C++ 2014.
 
template<unsigned n>
struct Arg {
template<class X, class…Xs>
constexpr auto operator()(X x, Xs…xs) {
return Arg<n-1>{}(xs…);
}
};
 
Not very readable, I agree with the author of that piece. And that is
replaced by:
 
template<unsigned n>
struct Get {
template<class X, class…Xs>
constexpr auto operator()(X x, Xs…xs) {
if constexpr(n > sizeof…(xs) ) {
return;
} else if constexpr(n > 0) {
return Get<n-1>{}(xs…);
} else {
return x;
}
}
};
 
in C++ 2017.
 
The use case is:
 
// arg<2>(0,1,2,3,4,5) == 2;
 
OK. You want to access the arguments of a function *by position*. Using
*names* for arguments is much better in my humble opinion, and both the
example and the solution in C++ 2017 can't escape the fact that is much
better to access arguments by their names... if any. In the case of
functions with a variable arguments list, you can (and should) use
default arguments for them, i.e. documented default args readable in the
function declaration.
 
What strikes me is that the only use case that the author tried to
figure out was a solution to a non-existing need: accessing your
arguments by a hard coded number.
 
Let's go on to the second case where the improvements should be needed.
 
C++ 2014:
template<class T>
auto compute(T x) -> decltype( enable_if_t< supportsAPI(T{}), int>{}) {
return x.Method();
}
 
You have to define the negative method that I do not show here since it
differs by a "!" only, in the condition above.
 
C++ 2017:
template<class T>
int compute(T x) {
if constexpr( supportsAPI(T{}) ) {
// only gets compiled if the condition is true
return x.Method();
} else {
return 0;
}
}
 
Yes. Obviously writing:
auto compute(T x) -> decltype( enable_if_t< supportsAPI(T{}), int>{})
 
is longer than
 
if constexpr( supportsAPI(T{}) )
 
Neat. Is that, however, a real need for so many programmers that the
whole language needs to be updated to support a shorter construct?
 
And what about C?
 
#if defined(API_3_5_8)
 

No comments: