Friday, January 27, 2017

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

"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jan 27 07:51AM -0800

Following a post in comp.lang.c:
 
https://groups.google.com/d/msg/comp.lang.c/k3mIThpIDlM/hNNnatCPAwAJ
 
David Brown suggested the concept I convey below is templates, and that
I continue this discussion here:
 
"The quick answer is 'templates'. Details should probably be taken
to C++, if you really are interested in knowing about them."
 
The specific portion summed up here:
 
-----[ Begin ]-----
 
In the following example, I am able to take a defined block and
copy it into another function so as to prevent the dispatch of
the callback function call:
 
block my_qsort_compare
{
input left as SStruct1*, right as SStruct1*;
 
if (left->value > right->value) result = 1;
else if (left->value < right->value) result = -1;
else result = 0;
 
output result;
}
 
Then in a modified qsort_block() version, I could provide params:
 
qsort_block(&data[0], count, data_size,
my_qsort_compare, sizeof(my_qsort_compare));
 
The qsort_block() function copies in the block of code so that it
doesn't have to issue function call dispatches, but inlines the
logic through some kind of established input and output protocols
where parameters enter and exit knowingly without going through
the stack, but reference wherever they already are in the specific
instance use.
 
-----[ End ]-----
 
So ... how do templates allow the my_qsort_compare block of code so
that it could be generated at compile time in a generic manner able
to be copied into qsort_block() (to save the function call overhead)?
 
Thank you,
Rick C. Hodgin
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Jan 27 04:45PM

On 27/01/2017 15:51, Rick C. Hodgin wrote:
 
> So ... how do templates allow the my_qsort_compare block of code so
> that it could be generated at compile time in a generic manner able
> to be copied into qsort_block() (to save the function call overhead)?
 
You see I know the answer to your question but I am not going to give
you it unless you promise to stop with the Christian bullshit posts to
this newsgroup. I hope others will follow my lead.
 
/Flibble
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jan 27 08:52AM -0800

On Friday, January 27, 2017 at 11:46:05 AM UTC-5, Mr Flibble wrote:
 
> You see I know the answer to your question but I am not going to give
> you it unless you promise to stop with the Christian .. posts to
> this newsgroup. I hope others will follow my lead.
 
Your pattern follows a known pattern:
https://groups.google.com/d/msg/comp.arch/vFwmR11a7AE/mDcMFGZ6DwAJ
 
My pattern also follows a known pattern:
https://groups.google.com/d/msg/comp.arch/vFwmR11a7AE/eM4KQol_DwAJ
 
Mr. Flibble ... I care too much about you to honor your request, or
Mitch's request.
 
Thank you,
Rick C. Hodgin
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jan 27 10:36AM -0800

On Friday, January 27, 2017 at 11:46:05 AM UTC-5, Mr Flibble wrote:
 
> You see I know the answer to your question but I am not going to give
> you it unless you promise to stop with the Christian bullshit posts to
> this newsgroup. I hope others will follow my lead.
 
You have been given a lot of information in your life, Leigh. You've
been educated in things, had various jobs, opportunities to personally
study. You've honed your life into a well-powered machine capable of
approaching countless tasks, and mastering them fully. You command a
great set of skills in all you do.
 
You must come to realize that those were all given to you by God. Even
the times you had to work a job to get money to pay for education, or
whatever it was, God gave you the ability to do all of those things.
 
He has a plan for you in your life. He has a purpose for you to serve
Him in this world. He has a purpose for all of the skills and crafts
and abilities and knowledge He's given you, and they all involve a
direct purpose and focus on helping other people, and not in hoarding
that knowledge in any capacity.
 
You will personally be held accountable for what you did with His gifts
to you. By denying me or anyone else the knowledge you were freely
given, you will give an account before God for that decision ... and it
will not bode well for you.
 
Consider that the next time you have the capacity to help another, and
choose voluntarily to withhold that information.
 
And FWIW, I forgive you (and Mitch) for not helping me, so you will not
be able to summon me as a witness against you in your case. God Himself
will summon me as a witness, and I will tell Him the truth. But I have
personally discharged you of any wrongness toward me, so you will stand
before Him and Him alone giving an account. I will not accuse you, but
I will be forced to answer His questions truthfully.
 
Thank you,
Rick C. Hodgin
Ian Collins <ian-news@hotmail.com>: Jan 28 10:35AM +1300

On 01/28/17 05:45 AM, Mr Flibble wrote:
 
> You see I know the answer to your question but I am not going to give
> you it unless you promise to stop with the Christian bullshit posts to
> this newsgroup. I hope others will follow my lead.
 
What he said. You can't flout the Usenet rules of common decency by
spamming and then expect help.
 
--
Ian
Gareth Owen <gwowen@gmail.com>: Jan 27 09:38PM

>> this newsgroup. I hope others will follow my lead.
 
> What he said. You can't flout the Usenet rules of common decency by
> spamming and then expect help.
 
Yeah, I'm with Ian and Mr Flibble
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jan 27 01:44PM -0800

You are not harming me by not helping me, because I am legitimately
coming before you asking for help. But there are potentially many
being harmed by you not helping me. It is not me you will be
accountable two for harming them, but it is your very maker.
 
It's why I teach you about sin, about the Lord, about forgiveness
and repentance. It's so you won't stand guilty before God, and
will not be injured by your sinful actions. I want you to be
stripped of your sin by Jesus, just as He stripped me of my sin,
so that you and I stand before God faultless, blameless.
 
I pray you consider deeply these words. Your eternal soul is
riding on whether or not you accept His free offer of forgiveness.
 
Thank you,
Rick C. Hodgin
woodbrian77@gmail.com: Jan 27 12:02PM -0800


> I'm not sure if you mean to use string_view in the implementation
> or in the class/constructor interface. I've thought about using it
> in the interface, but haven't gotten there yet.
 
I changed a constructor in that class to take a string_view:
 
https://github.com/Ebenezer-group/onwards/blob/master/ErrorWords.hh
 
. Now I'm wondering if anyone has written a composite type trait --
something like is_stringy -- that returns true if T is a std::string,
std::string_view, char*, or char const*. I have these 4 functions:
 
failure& operator<< (::std::string const& s);
failure& operator<< (::std::string_view const& s);
failure& operator<< (char* s);
failure& operator<< (char const* s);
 
that all have the same implementation. An is_stringy would help
me clean that up. With the advent of string_view, it's a good
reminder to do something about this.
 
 
 
Brian
Ebenezer Enterprises - 7 days without prayer makes one weak.
http://webEbenezer.net
"Christopher J. Pisz" <cpisz@austin.rr.com>: Jan 27 02:42PM -0600


> Brian
> Ebenezer Enterprises - In G-d we trust.
> http://webEbenezer.net
 
what's this C++17 stuff? I dunno what a string view is yet, as opposed
to a string. Either, way, what's wrong with the char * you get now? When
I derive from a std::exception, I can just constuct my string when I
need it, and who cares about the copy? It's an exception, which should
occur exceptionally.
woodbrian77@gmail.com: Jan 27 01:18PM -0800

On Friday, January 27, 2017 at 2:42:12 PM UTC-6, Christopher J. Pisz wrote:
> > http://webEbenezer.net
 
> what's this C++17 stuff? I dunno what a string view is yet, as opposed
> to a string. Either, way, what's wrong with the char * you get now?
 
Why pay for what you don't need?
If you have a std::string, and a lot of people do, you can avoid
throwing away the length by using string_view rather than char*.
 
 
> I derive from a std::exception, I can just constuct my string when I
> need it, and who cares about the copy? It's an exception, which should
> occur exceptionally.
 
The faster you handle an exception, the sooner you will be
able to encounter the next one.
 
 
Brian
Ebenezer Enterprises - "No man ever listened himself out of a job."
Calvin Coolidge
 
http://webEbenezer.net
Ian Collins <ian-news@hotmail.com>: Jan 28 10:37AM +1300

On 01/28/17 09:42 AM, Christopher J. Pisz wrote:
 
> I derive from a std::exception, I can just constuct my string when I
> need it, and who cares about the copy? It's an exception, which should
> occur exceptionally.
 
Indeed. The cost of throwing far outweighs the cost of generating a string.
 
--
Ian
Ramine <toto@toto.net>: Jan 27 09:35PM -0500

Hello..
 
 
My C++ synchronization objects library was updated..
 
My scalable DRWLock and scalable DRWLockX were updated, i have optimized
them more, and now they are faster.
 
You can download the new updated Linux and the Windows versions from:
 
https://sites.google.com/site/aminer68/c-synchronization-objects-library
 
 
Thank you,
Amine Moulay Ramdane.
JiiPee <no@notvalid.com>: Jan 27 11:14AM

This is one of the best newsgroup I have been. Also been learning many
practical small details (like recently that the compiler would optimze
off an empty function... obvious for many (and now for me as well) but I
never thought about that).
 
 
I have solved many problem in my real projects here.
 
And seems like many experts answering here. Good idea indeed developers
supporting each others.
 
Would consider even paying to be here, but its free...
 
 
So thumbs up.
"Christopher J. Pisz" <cpisz@austin.rr.com>: Jan 27 02:43PM -0600

On 1/27/2017 5:14 AM, JiiPee wrote:
 
> Would consider even paying to be here, but its free...
 
> So thumbs up.
 
I learned more C++ here then in any college course or any book.
A lot of the original crew hasn't shown up as often or at all anymore
though. I wonder if they are just old men now.
"Christopher J. Pisz" <cpisz@austin.rr.com>: Jan 27 09:17AM -0600

I am going to be looking up whether or not my custom data structure
contains a string one character at a time.
 
For example:
 
Check "c"
Check "ca"
Check "cat"
Check "cate"
Check "categ"
..
Check "category"
...
 
All I need to know is if my data structure contains the string or not.
 
I was thinking of trying to implement my own Radix Trie.
https://en.wikipedia.org/wiki/Radix_tree
 
I'd give it a method contains and see if any node in the Trie contains
the string in question.
 
It will only contain the actual full words, but allow me to search for
the words as they are being typed out.
 
When doing insertions into this data structure, it appears as though I
am going to do a std::string find on all children to find if the value
and the node/edge (depending on how I implement) has characters in
common and how many.
 
How complex is std::find(substr, offset)?
I wonder if I am barking up the wrong tree.
"Christopher J. Pisz" <cpisz@austin.rr.com>: Jan 27 09:39AM -0600

On 1/27/2017 9:17 AM, Christopher J. Pisz wrote:
> common and how many.
 
> How complex is std::find(substr, offset)?
> I wonder if I am barking up the wrong tree.
 
 
Nm. I don't think I'll be using std::string find at all. Since I am
always comparing string at position 0. I guess I am looking at O(n) for
equality basically.
Paavo Helde <myfirstname@osa.pri.ee>: Jan 27 05:43PM +0200

On 27.01.2017 17:17, Christopher J. Pisz wrote:
> common and how many.
 
> How complex is std::find(substr, offset)?
> I wonder if I am barking up the wrong tree.
 
www.cplusplus.com says about string::find complexity: "Unspecified, but
generally up to linear in length()-pos times the length of the sequence
to match (worst case)."
 
The non-worst-case complexity is most probably just linear in length()-pos.
 
Anyway, from your descriptions it looks like you are trying to match
beginnings of words. If so, you should put these words in a map or set
and use lower_bound() for looking up the start point of the stretch of
the matching words.
 
hth
Paavo
Tim Rentsch <txr@alumni.caltech.edu>: Jan 26 11:54PM -0800

> for generic programming. In concepts, Stroustrup sees the solution to
> the interface specification problem that has long dogged C++, the
> language he founded more than 35 years ago."
 
My sense is this capability will be a useful addition to C++.
(That is, assuming it gets nailed down well enough and has the
kinks worked out of it, which I wasn't able to figure out from
reading the paper.)
 
Two complaints: the term "concepts" just isn't a good word
choice for what's being added. Also, the writing is a bit
offputting in its tone and style; IMO the author (and yes
I know who the author is) is rather too full of himself, and
the writing suffers because of that.
Manfred <noname@invalid.add>: Jan 27 01:59PM +0100

On 1/27/2017 8:54 AM, Tim Rentsch wrote:
> Two complaints: the term "concepts" just isn't a good word
> choice for what's being added.
I tend to agree on this. The term is attractive for its generality (btw
concepts are the foundation of human knowledge, so, what a big
thing(!)), but in fact too generic for the task it represents;
When defining the term, Bjarne himself writes (page 2):
<<The solution to the interface specification problem was named
"concepts" by Alex Stepanov (§8.8). A concept is a set of requirements
on a set of template arguments.>>
 
Well then, A concept is a set of requirements on a set of template
arguments. So what about 'requirement', 'constraint' or anything that
describes what this thing is doing?
 
Also, the writing is a bit
> offputting in its tone and style; IMO the author (and yes
> I know who the author is) is rather too full of himself, and
> the writing suffers because of that.
I don't think that the author is too full of himself. But the choice of
the name (too big) might have been influenced by his enthusiasm.
Tim Rentsch <txr@alumni.caltech.edu>: Jan 27 12:04AM -0800

> as far as C is concerned the state is not only persistent but also it
> must be honoured. The program above should not print the second line on
> a conforming implementation.
 
Just a short comment here. I agree with your analysis, but note
that the Standard's description regarding EOF changed between C90
and C99. In C90 I believe the observed behavior is conforming,
or at least arguably conforming. (Let me add that I have not
gone through any DR's or other documents to see when the newer
requirements may have come into force.)
Tim Rentsch <txr@alumni.caltech.edu>: Jan 26 11:42PM -0800


> Oh.
 
> You probably have some good points even though it seems clear that you
> have more of a C background than C++, and I'd love to hear them.
 
A short afterthought to my long posting - I hope it didn't
come across as preachy, I didn't mean it that way at all;
just an explanation of my previous comment.
 
Incidentally, I am ready with an explanation for how to do
threading if/when you would like to hear that. I didn't
want to get ahead of the rebalancing installment.
Tim Rentsch <txr@alumni.caltech.edu>: Jan 26 11:37PM -0800


>> So, for what it's worth, that is now the best suggestion I have
>> to offer.
 
> Sorry for being very slow about things.
 
No worries!
 
> Anyway I've started on this road now, though not with AWK, which I
> just barely remember from ?The UNIX Programming Environment? long long
> ago?
 
Yes, personally I find awk quite a handy tool, but it is
no doubt cryptic for those who aren't used to it. Here
is the same conversion program (with a small fix) done
using grep and sed in a shell script:
 
#! /bin/sh
 
cat "$@" | \
grep HANDLE_WM_ | \
sed 's/(fn)((hwnd),/(fn)(/' | \
sed 's/(fn)(hwnd,/(fn)(/' | \
sed 's/(fn)(hwnd)/(fn)()/' | \
sed 's/(hwnd,/(fn,/' | \
sed 's/,fn)/)/' | \
sed 's/ HANDLE_/ CRACK_/' | \
cat
 
 
> Void` return type instead of plain `void` is in order to be able to
> wrap calls of the handlers in a single general dispatcher.
 
> [snip elaboration, ~200 lines of C++, and ~150 lines of output]
 
I think I follow what you're doing, well, sort of. I'm not sure
how it connects to the original problem.
 
 
> So, I've made some progress on this, taking your advice ? perhaps
> taking it more far than you intended. :)
 
My sense is you are taking a different approach, and at a higher
level, to solve a more general problem statement. It's hard for
me to give a useful response, what with not being sure about what
the problem statement is, and also not understanding the proposed
solution. :) But as long as you're happy with the direction
you're going I am glad to have been of help.
Tim Rentsch <txr@alumni.caltech.edu>: Jan 26 11:11PM -0800


> Using macro seems to be the only way to do this trace so that the
> release version ignores that line and does not compile it. How would
> "dont-use-macros" person do this other way?
 
IME some segements of the C++ community are overly dogmatic in
wanting to avoid using macros. Depending on the specifics, there
may be a way to implement a Trace() construct that doesn't use
macros (as others have explained), or in other cases macros may
be essentially the only viable choice (again per other posters).
I suggest choosing the approach that you think makes the most
sense, considering both current requirements and likely future
requirements. If someone suggests a different design choice
would be better, do listen carefully but then decide whether the
reasons offered make sense or if they are just being dogmatic.
Tim Rentsch <txr@alumni.caltech.edu>: Jan 26 10:40PM -0800

>> because you don't know ahead of time how many elements will be in
>> each partition.
 
> Every second time you add to the list, advance the "middle" iterator.
 
Yes, I didn't say impossible, just a little tricky. And the
details change if one is dealing with an ordinary linked list
(as I was imagining) rather than an iterable one.
 
> Sure, that adds a bit to the constant factor of the complexity, but
> on the other hand it may be worth it, if the median-of-three pivot
> choice compensated for it on average.
 
All things considered, it probably makes more sense to select
three elements at random during the scan, and use the median of
those three random elements as the pivot.
Marc Beauchesne <marc.beauchesne@gmail.com>: Jan 26 06:20PM -0800

It's using Template Argument Deduction. In this case, you specify R, but A is deduced from the type you supply as an argument. You can read more about it in the link below or in your favorite reference manual.
 
http://en.cppreference.com/w/cpp/language/template_argument_deduction

 
On Friday, January 27, 2017 at 6:46:49 AM UTC+8, Christiano wrote:
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: