Saturday, March 19, 2016

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

"Öö Tiib" <ootiib@hot.ee>: Mar 19 04:50AM -0700

On Saturday, 19 March 2016 01:18:28 UTC+2, bitrex wrote:
> {
> return std::pow(x, 2);
> }
 
I do not understand what argument here can be. AFAIK it is ill-formed
code since 'std::pow' is not 'constexpr'. Standard-conformant
implementation must diagnose it as defective.
Almost none of the math functions can be 'constexpr', since these
contain the legacy requiment of setting 'errno' on various error
conditions, on case of 'pow' it is 'EDOM' AFAIK.
 
> //something
> };
 
> What is the "proper" way to do this?
 
What means "proper"? I would accept someone writing them all out manually,
making a tiny script for not doing it manually and perhaps even usage of preprocessor metaprogramming for generating the array.
bitrex <bitrex@de.lete.earthlink.net>: Mar 19 08:10AM -0400

On 03/19/2016 07:50 AM, Öö Tiib wrote:
 
>> What is the "proper" way to do this?
 
> What means "proper"? I would accept someone writing them all out manually,
> making a tiny script for not doing it manually and perhaps even usage of preprocessor metaprogramming for generating the array.
 
So there isn't a way to do this internally? The idea is that I don't
want to use an external script to generate the values, as then if
someone wants to modify the code for their own purposes the script needs
to be delivered along with it.
 
I know it's possible to do something like this with macro expansion
using the preprocessor:
 
http://lolengine.net/blog/2011/12/20/cpp-lookup-table-generation
 
but my table function requires more complicated math operations than
just shifts and bitwise ANDs, i.e. using the power function.
 
So I was wondering if there was a way to incorporate the latter with the
former "constexpr" feature.
Jorgen Grahn <grahn+nntp@snipabacken.se>: Mar 19 01:01PM

On Sat, 2016-03-19, bitrex wrote:
>> perhaps even usage of preprocessor metaprogramming for generating
>> the array.
 
> So there isn't a way to do this internally?
 
He didn't say that -- he just criticized your suggested solution for
not working, and asked you to explain better.
 
(Personally I don't see why you chose std::pow(x, 2) instead of x * x,
but maybe I'm missing something.)
 
/Jorgen
 
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
bitrex <bitrex@de.lete.earthlink.net>: Mar 19 09:03AM -0400

On 03/19/2016 09:01 AM, Jorgen Grahn wrote:
 
> (Personally I don't see why you chose std::pow(x, 2) instead of x * x,
> but maybe I'm missing something.)
 
> /Jorgen
 
Just for the purposes of illustration. In my actual code, I'll need to
use a moderately complicated equation involving e^x...
"Öö Tiib" <ootiib@hot.ee>: Mar 19 10:11AM -0700

On Saturday, 19 March 2016 14:10:52 UTC+2, bitrex wrote:
> want to use an external script to generate the values, as then if
> someone wants to modify the code for their own purposes the script needs
> to be delivered along with it.
 
I did not write that. I wrote that for me it is OK if you type it in
manually, to use a tool or to use preprocessor. If duck typing or using
a tool is not good for *your* purposes, then that leaves only preprocessor.
We can't say that it is more "proper" in general. In my experience a
maintainer can be confused with and mess up C/C++ preprocessor
metaprogramming far easier than anything else that is available in C++.
 
 
> I know it's possible to do something like this with macro expansion
> using the preprocessor:
 
> http://lolengine.net/blog/2011/12/20/cpp-lookup-table-generation
 
Rather advanced code generation is possible with C/C++ preprocessor.
For particular purpose perhaps download boost and check how
BOOST_PP_REPEAT is made. If dependency on Boost.Preprocessor is Ok
then use BOOST_PP_REPEAT itself. Otherwise you can still do "derivative
work" of it into your code-base. It works OK on compilers that I have
tried.
 
> just shifts and bitwise ANDs, i.e. using the power function.
 
> So I was wondering if there was a way to incorporate the latter with the
> former "constexpr" feature.
 
Sure, what I meant is that generating code is not issue. Issue is that
we can't use standard library math functions in 'constexpr' functions
without violating standard. GCC has indeed made non-conforming extension to
have standard math functions 'constexpr'. My opinion is that it is better
to use some other 'constexpr' math library instead of such extension
of particular compiler. History has shown that it brings less pain in
long run.
bitrex <bitrex@de.lete.earthlink.net>: Mar 19 06:14PM -0400

On 03/19/2016 01:11 PM, Öö Tiib wrote:
> to use some other 'constexpr' math library instead of such extension
> of particular compiler. History has shown that it brings less pain in
> long run.
 
Understood, thanks so much for your advice!
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Mar 18 11:49PM

On Fri, 18 Mar 2016 15:11:27 -0700 (PDT)
> On Friday, March 18, 2016 at 5:02:22 PM UTC-5, Mr Flibble wrote:
 
> Leigh, you are an anti-religious bigot.
 
He may be, but you are an absolute pest. This is a C++ newsgroup but
you repeatedly post off topic posts, mainly involving your religious
convictions.
 
Why don't you get your head out of your arse, realise that other people
might have rights other than just you, and fuck off to a group which
deals with religious issues.
 
YOU ARE OFF TOPIC.
 
Chris
Gareth Owen <gwowen@gmail.com>: Mar 19 06:14AM


>> IBM, American Express and Southwest Airlines have a combined operating
>> income of $26 billion. It seems that God has helped them a lot more.
 
> David against Goliath.
 
But David *won* because God favoured him. If your story is David
v. Goliath, with God favouring you -- aren't you supposed to be winning?
 
Did I miss the point of David v. Goliath?
 
Is it possible that Goliath won, but that David kept changing Wikipedia
to make it look that he had won?
 
>> Could it be that not being a judgmental asshole is more pleasing to God?
 
> If speaking up for babies and children is being judgmental, so be it.
 
What the hell does gay marriage have to do with babies and children?
"Öö Tiib" <ootiib@hot.ee>: Mar 19 02:11PM -0700


> I admit to being a Yeshua (Jesus) Freak. G-d died for my
> sins and I owe everything to Him.
 
I also like Jesus of Nazareth. Godhood, miracles or raising
from death can not impress me. I can't believe those things since I am
atheist. I like everything else of him that is left over. His teaching of
goodness. Violence has always raised more violence. Martyrdom of likes
of Jesus of Nazareth (or many others like Giordano Bruno) however
feels pure to me and it has changed our civilization to better one
every time.
 
Why you need to think that you are like Noah or Moses that saves world
from God's wrath or Pharaoh's chariots through miracle? That is way to
insanity ... the way of The Ingenious Gentleman Don Quixote of La Mancha.
Better be a good and beneficial to people person and they will like
you.
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Mar 19 09:57PM

On 19/03/2016 21:11, Öö Tiib wrote:
> insanity ... the way of The Ingenious Gentleman Don Quixote of La Mancha.
> Better be a good and beneficial to people person and they will like
> you.
 
Jesus of Nazareth never actually existed though. Some historical person
that Jesus might have been partially based on and Jesus are not the same
individual.
 
But this has very little to do with C++ and just feeds the trolls so I
will stop.
 
/Flibble
"Öö Tiib" <ootiib@hot.ee>: Mar 19 03:40AM -0700

On Thursday, 17 March 2016 16:10:31 UTC+2, JiiPee wrote:
> <http://en.cppreference.com/w/cpp/types/type_info>type) { ... } then it
> accepts many other types as well , other than animals type (it accepts
> any type_info).
 
Perhaps I do not understand what you mean. The 'typeid' returns an
object of type 'std::type_info' not type. Further, in well-defined
program an 'enum' object can have any state representable in underlying
to 'enum' type. That is because lot of existing code uses enums (instead
of better candidate 'std::bitset') to represent sets of flags.
So both with 'enum' and with 'type_info' you can have many wrong values
passed to your 'GetAnimal'.
 
Possibly the only benefit of 'enum' is that we can have integer value
that is same between program runs. Same can be achieved with lot less
tricks needed for example by using index value returned by
'boost::variant<all, animal, types, here>::which()' method.
JiiPee <no@notvalid.com>: Mar 19 11:06AM

On 19/03/2016 10:40, Öö Tiib wrote:
>> any type_info).
> Perhaps I do not understand what you mean. The 'typeid' returns an
> object of type 'std::type_info' not type.
 
yes, but I would like a type "animal_type", not std::type_info . why?
becouse std::type_info can be filled with , for example, car information
... or information about about suitcases, etc. But animal_type accepts
only animals....
 
Its the same with "int"- type. int can contain any integer
information... not only the size of the animal.
 
So I would like to limit the type to only have animal-type of
information so that the compiler would give an error if you try to pass
any other type of information
 
"Öö Tiib" <ootiib@hot.ee>: Mar 19 02:29PM -0700

On Saturday, 19 March 2016 13:07:07 UTC+2, JiiPee wrote:
> becouse std::type_info can be filled with , for example, car information
> ... or information about about suitcases, etc. But animal_type accepts
> only animals....
 
Oh then it seems I understood you correctly. If you want compile-time
diagnostics then neither 'enum animal_type' nor 'std::type_info' can help
you so you are in deep confusion.
Paavo Helde <myfirstname@osa.pri.ee>: Mar 19 01:32AM +0200

On 19.03.2016 0:55, Lynn McGuire wrote:
> Well, I just got educated on virtual method calls in constructors and
> destructors. None will be executed as you think so that functionality
> will not work. It would be nice if the compiler would warn a person.
 
In C++ the virtual method call from ctor/dtor works exactly like I am
expecting (unlike in some other language). It would not make sense to
call a function on an object which is not yet constructed or is already
destroyed, would it?
 
The point is, both the construction and destruction already behave
pretty polymorphically, all the inheritance chain is traversed and all
the ctors/dtors called on the way. That's about the same behavior which
can be achieved by virtual functions, so there should be no real need to
call virtual functions from ctors/dtors.
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Mar 19 07:00AM +0100

On 18.03.2016 23:55, Lynn McGuire wrote:
> Well, I just got educated on virtual method calls in constructors and
> destructors. None will be executed as you think so that functionality
> will not work.
 
On the contrary, in C++ virtual functions are executed in the same way
from constructors and destructors as from elsewhere.
 
And unlike Java and C#, in C++ it's safe.
 
So, generally, it Just Works™, in C++.
 
 
> It would be nice if the compiler would warn a person.
 
> http://stackoverflow.com/questions/12092933/calling-virtual-function-from-destructor
 
That answer is a bit of FUD: Fear, Uncertainty and Doubt. Silly in a
technical context. But good for harvesting some rep points at SO, which,
after all, is the absolutely greatest extant Herb Schildt area on the
Internets :)
 
 
> and
 
> http://stackoverflow.com/questions/9114982/calling-virtual-method-from-destructor-workaround
 
Uhm, too long didn't read, but it's a typical X/Y-question: wanting to
do X, envisioning solution Y, finding that Y is impossible or
impractical (usually complete nonsense), asking about Y only.
 
 
> I devised a way to get around the virtual method call in the constructor
> by adding an argument to my base constructor which fixed that issue.
 
I guess you want to do derived class specific initialization WITHIN the
base class constructor, e.g. creating a Button API-level widget in the
constructor of a general Widget base class constructor.
 
Hurray, the FAQ is there for you!
 
https://isocpp.org/wiki/faq/strange-inheritance#calling-virtuals-from-ctor-idiom
 
Re terminology: AFAIK the "Dynamic Binding During Initialization" term
is just something Marshall Cline invented, it wasn't there in my
original FAQ suggestion, and I've never seen it anywhere else.
 
 
> But getting around the virtual method call in my destructor is painful.
 
That's the Y of an X/Y problem. ;-)
 
What is the /real/ problem, that you try to solve that way?
 
 
Cheers & hth.,
 
- Alf
Bo Persson <bop@gmb.dk>: Mar 19 11:35AM +0100

On 2016-03-18 23:55, Lynn McGuire wrote:
 
> I devised a way to get around the virtual method call in the constructor
> by adding an argument to my base constructor which fixed that issue.
> But getting around the virtual method call in my destructor is painful.
 
It works exactly the way it was designed.
 
When the base class destructor runs, the derived class' destructor has
already been executed, and that part of the object is gone. Calling a
function of the derived class is the same as calling a function of a
deleted object.
 
C++ protects you from that. A good thing!
 
To me, the very obvious "workaround" is for the derived class'
destructor to call its own function as needed. That way the base class
doesn't have to.
 
 
Bo Persson
ram@zedat.fu-berlin.de (Stefan Ram): Mar 19 04:38AM

> //something
>};
>What is the "proper" way to do this?
 
Reminds of the old joke: When a programmer is paid by the
line of code, how do you think an array is initialized to
zero?
Lynn McGuire <lmc@winsim.com>: Mar 18 09:31PM -0500

"Q&A: Bjarne Stroustrup previews C++ 17"
http://www.infoworld.com/article/3044727/application-development/qa-bjarne-stroustrup-previews-c-17.html
 
"The new version due later this year will feature parallel algorithms, but Concepts, modules, and co-routines will have to wait for a
future upgrade"
 
I thought Infoworld was dead.
 
Lynn
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: