Monday, April 13, 2015

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

Doug Mika <dougmmika@gmail.com>: Apr 13 10:35AM -0700

Hi to all, I was wondering what overloading the operator() is?
I know that overloading an operator< allows for the direct comparison of my two objects using <, but what about the operator(), especially in a struct? Does it allow the struct to be called like a function?
 
// list::remove_if
#include <iostream>
#include <list>
 
// a predicate implemented as a function:
bool single_digit (const int& value) { return (value<10); }
 
// a predicate implemented as a class:
struct is_odd {
bool operator() (const int& value) { return (value%2)==1; }
};
 
int main ()
{
int myints[]= {15,36,7,17,20,39,4,1};
std::list<int> mylist (myints,myints+8); // 15 36 7 17 20 39 4 1
 
mylist.remove_if (single_digit); // 15 36 17 20 39
 
mylist.remove_if (is_odd()); // 36 20
 
std::cout << "mylist contains:";
for (std::list<int>::iterator it=mylist.begin(); it!=mylist.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
 
return 0;
}
 
thanx
Victor Bazarov <v.bazarov@comcast.invalid>: Apr 13 02:58PM -0400

On 4/13/2015 1:35 PM, Doug Mika wrote:
> Hi to all, I was wondering what overloading the operator() is?
 
It's called "operator function call". What book are you reading that
does not explain it?
 
> I know that overloading an operator< allows for the direct
> comparison
of my two objects using <, but what about the operator(), especially in
a struct? Does it allow the struct to be called like a function?
> std::list<int> mylist (myints,myints+8); // 15 36 7 17 20 39 4 1
 
> mylist.remove_if (single_digit); // 15 36 17 20 39
 
> mylist.remove_if (is_odd()); // 36 20
 
That's a call to the template function 'remove_if' and providing a
temporary object as its argument. You need to understand what
'remove_if' does in order to comprehend this fully. Step into it using
your debugger, and take a good look at the code.
 
> std::cout << '\n';
 
> return 0;
> }
 
Predicates designed to work with standard functions like 'for_each',
'copy_if', etc., need to provide a special member function - the
operator function call, with a particular argument number and types.
 
Get yourself a decent book on C++ and read it. Daily.
 
V
--
I do not respond to top-posted replies, please don't ask
if <if@invalid.invalid>: Apr 13 10:20AM +0200

Freemasonry although the first steps or compartments seems
harmless then in the higher levels is revealed what it is:
use magic and worship of satan
and its fruits can not lie...
 
also there is no good in the win on others
with the secret and unjustly
using the group or people one known
 
la massoneria anche se ai primi scalini o compartimenti
sembra innocua poi nei livelli più alti si rivela
quello che è: magia e adorazione di satan
e i suoi frutti non possono mentire...
 
inoltre non c'e' nessun bene nel prevalere sugli altri
col segreto e ingiustamente
facendosi forza del proprio gruppetto o persone conosciute
 
testimonianza di un fuoriuscito
https://www.youtube.com/watch?v=5XDCstYCY2g
bartek <bartek@gmail.com>: Apr 13 01:16PM +0200

On 13.04.2015 10:20, if wrote:
 
> also there is no good in the win on others
> with the secret and unjustly
> using the group or people one known
 
What library do you use? I stick with our 'almost standard'.
boost::constructions::masonry
boost::supernatural::evil::satan
And I don't see any interferences.
 
The first library is very fast way to build NWO application,
and the second works great with Oculus Rift.
 
 
bartekltg
scott@slp53.sl.home (Scott Lurndal): Apr 13 01:45PM

>And I don't see any interferences.
 
>The first library is very fast way to build NWO application,
>and the second works great with Oculus Rift.
 
No, he posted to the wrong group. Masons use the Acacia
language, designed originally by Hiram Abiff.
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Apr 13 06:12PM +0100

On 13/04/2015 14:45, Scott Lurndal wrote:
>> and the second works great with Oculus Rift.
 
> No, he posted to the wrong group. Masons use the Acacia
> language, designed originally by Hiram Abiff.
 
Sausages.
 
/Flibble
Juha Nieminen <nospam@thanks.invalid>: Apr 13 12:36PM

> "Trickery" implies, as I understand the word, something devious and
> undocumented that you're not supposed to learn about.
 
I was using the word to mean a technique that's non-trivial, non-obvious
and requires a deeper understanding of how the (template) mechanism
works and, to some extent, using the "side-effect" of a feature to
achieve what you want. (This doesn't mean that using the feature in
that manner is not fully standard.)
 
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
Robbie Hatley <see.my.sig@for.my.address>: Apr 12 05:20PM -0700

On 3/29/2015 5:14 AM, Nobody wrote:
 
 
> In short, for all its advantages, UTF-8 isn't magically immune to
 
> http://xkcd.com/927/
 
Harrumpf. Amusing, but in the Internet and Perl communities, pretty
far from the truth. The following is tongue-in-cheek, but still
kinda accurate in those communities:
 
DEFINITIONS:
"Character Set" = utf8
"Character Encoding" = utf8
"Unicode" = utf8
"Character" = utf8 entity (visual)
"Grapheme" = utf8 entity (visual, w/o adornments)
"Grapheme Cluster" = utf8 entity (visual, with adornments)
"Code Point" = utf8 entity or subentity (numerical)
 
Obviously in other sub-fields of computer science this is much less
true. But I hope that eventually all the other versions of Unicode
go extinct (or get relegated to special purposes) so that for the
most part "Unicode" = "utf8".
 
And hopefully before too long, C and C++ will do as Perl has done
and incorporate utf8 handling so that it becomes the standard for
handling text. (Or, at least, make it easy to switch between
ASCII and utf8.) And "Unicode Collate" should be part of the
Standard Library for sure.
 
Also, it would be nice to be able to say the following in
C++ source code:
 
double 富士川町年齢 = 58.836; // median citizen age in Fujikawa
int 富士川町猫 = 4378;  // number of cats in Fujikawa
 
You can already do that in some programming languages.
Just, not in C or C++. Yet.
 
 
--
Cheers,
Robbie Hatley
Midway City, CA, USA
perl -le 'print "\154o\156e\167o\154f\100w\145ll\56c\157m"'
http://www.well.com/user/lonewolf/
https://www.facebook.com/robbie.hatley
Richard Damon <Richard@Damon-Family.org>: Apr 12 09:46PM -0400

On 4/12/15 8:20 PM, Robbie Hatley wrote:
> int 富士川町猫 = 4378;  // number of cats in Fujikawa
 
> You can already do that in some programming languages.
> Just, not in C or C++. Yet.
 
Note that this it is explicitly defined that an implementation allow
such code. The implementation can use Unicode (any of utf8, utf16, or
ucs-4) as its character set, and
"identifier-nondigit" (which identifiers can be made from) explicitly
list "other implementation defined characters", like much of the unicode
character space.
 
Yes, you make you program dependent on an implement defined behavior,
but in some cases that is acceptable.
Robbie Hatley <see.my.sig@for.my.address>: Apr 13 01:43AM -0700

On 3/28/2015 8:37 AM, Richard Damon wrote:
 
> ...Now, if you actually want to count "Characters" in Unicode,
> you need to be fully Unicode aware, as this is a complicated
> attribute...
 
So, what you're saying is, a C++ program is unlikely to realize
(without a *LOT* of help from the programmer) that this string:
 
̵̡̧͈̤̯̰̫̥̭͓̮̱͖̻̞̪̻ͫ̇̔̾̏ͧ͑ͫ͊̾͆͋̆̈́ͩ̒̕p̛̾́̾̋͐ͣ̑̈̄̃̉͂̒͗ͫͦ̏̀ͮ͠҉̧͉̥̝̲̞̱̱̺̬ō̵̧̡̙̪̲̙̤̥͙̯̬̘̺̝͈̰̳͓̑̂̆̓̔ͧ̓̈́ͫͯ̕s̛̔ͬ̄͌̊͊̌͐̃̅̋̓̽҉͏̵̤̟̬̰͇̖̭̺̳̠̫̜̪́ͅi̽ͮ̽͂͒͌̋͊̀ͦ̒͌̏͛ͤͯͯ҉̨̪͖̜̙̮̼͈̠͚̦͚͢͡t̸̢͍̩̯͈̣̫͚̯̟̳͈̻̘̣̮̠͗̐͊̌̑̋͐͒͂ͥ̽͒ͮ͌ͧ͛ͧ̅̚͞͝i̢͋ͫ̆͗̉͐ͤ͊ͨ̓̾̏͏͔̘͇͓̰͔̰͈͚͍̠̺̯̥̻̠̫̘̀ô̷̹̮͔̬̹͚̺̼̱̠̖̋̂͛̈ͦ͋ͦͭͬ̔̀͘ņ̢͕͚̰̼̞̼͇̥̻̥͎̮̱͗ͪͦͭͫ̆ͤͧͪ̓͆͆̓ͧ͂̏͝
 
is actually just 8 characters, even though it's 590 bytes. :D
Though I must say, that's a pretty egregious abuse of the
concept of "Grapheme Clusters".
 
 
 
 
--
Cheers,
Robbie Hatley
Midway City, CA, USA
perl -le 'print "\154o\156e\167o\154f\100w\145ll\56c\157m"'
http://www.well.com/user/lonewolf/
https://www.facebook.com/robbie.hatley
Robbie Hatley <see.my.sig@for.my.address>: Apr 13 02:24AM -0700

On 3/30/2015 2:57 AM, Juha Nieminen wrote:
 
> What exactly would make it crash? The fact that the bytes just happened
> to be in a form specified by some UTF-8 specification makes no
> difference. They are just bytes.
 
I'm beginning to appreciate that. Which is kinda cool, because
it means that some (but not all) operations with utf8 can be
done in C++ exactly as if you were using ASCII or ISO-8859-1.
 
> If you want to interpret the input as UTF-8 in your program, you need
> to use some library for that. std::string itself is not enough for
> that kind of operation.
 
I'm guessing that sometimes one could get away with that.
 
But sometimes not.
 
Let's run the following test. I have a C++ program that sorts and
dedups the lines of text in a text file. (Useful for lists of
things such as names, though would make garbage of normal text.)
The program looks like this (simplified for brevity):
 
int main (int Thyme, char *Sage[])
{
// Make a list of strings called "Text":
static std::list<std::string> Text;
 
// Read input from cin to Text:
ReadInput(Text);
 
// Sort the list of strings:
Text.sort();
 
// Remove duplicate lines from Text:
Text.unique();
 
// Write output from Text to cout:
WriteList(Text);
 
return 0;
}
 
(where the functions mentioned do what their names say)
 
Let's give it this input:
 
Kate Onthetimeline
Chasity Ahmad
Collin Tierney
Ed Gooz
Frederic Moseley Jr.
John Froex
Amanda Alatti
Emirjon Fishta
Lisa Lauchstedt
Mary Elizabeth Blackley
Zackry Wallace-Bell
İrfan Qureyş
Padraic O'Driscoll
Nékoé Mīkûriá
Arthur Vullamparthi
Ragu PG
Nathan Gutierrez
Sifokl AlSifokli
Tammy Houghtaling
Yuri Aleksei Carrión Belliard
 
And what I get back is:
 
Amanda Alatti
Arthur Vullamparthi
Chasity Ahmad
Collin Tierney
Ed Gooz
Emirjon Fishta
Frederic Moseley Jr.
John Froex
Kate Onthetimeline
Lisa Lauchstedt
Mary Elizabeth Blackley
Nathan Gutierrez
Nékoé Mīkûriá
Padraic O'Driscoll
Ragu PG
Sifokl AlSifokli
Tammy Houghtaling
Yuri Aleksei Carrión Belliard
Zackry Wallace-Bell
İrfan Qureyş
 
Which is, for the most part, exactly the sorting you expect, except
that "İrfan Qureyş" has been moved to the end due to the single
umlaut above the "I". Unless you got lucky and the "İ" was in
it's "fully decomposed" encoding ("I" plus umlaut as combining mark),
that would be likely to happen to any line starting with a letter
using a diacritical mark. Also, lines sorting with capital letters
would sort before lines starting with small letters.
 
Which is why I think C++ needs a "UnicodeCollate" function in its
std lib.
 
 
(Disclaimer: The names listed are random names for software testing
only; any resemblance to actual people, living or dead, is purely
coincidental.)
 
 
--
Cheers,
Robbie Hatley
Midway City, CA, USA
perl -le 'print "\154o\156e\167o\154f\100w\145ll\56c\157m"'
http://www.well.com/user/lonewolf/
https://www.facebook.com/robbie.hatley
Ben Bacarisse <ben.usenet@bsb.me.uk>: Apr 13 12:56PM +0100


> On 3/30/2015 2:57 AM, Juha Nieminen wrote:
<snip>
> would sort before lines starting with small letters.
 
> Which is why I think C++ needs a "UnicodeCollate" function in its
> std lib.
 
Did you try with
 
Text.sort(std::locale(""));
 
maybe with a suitable string there if your environment does not define
the locale correctly for that input? This won't address all Unicode
encoding and collating issues by any means, but it's a first step that
might be enough for simple programs.
 
--
Ben.
ram@zedat.fu-berlin.de (Stefan Ram): Apr 13 01:21AM

>double ? = 58.836; // median citizen age in Fujikawa
>int ? = 4378;? // number of cats in Fujikawa
 
You can do it in Java since 1995. But no one uses it,
because they are afraid that other people in the project
might not be prepared to read, edit or write such names.
 
My Newsreader also does not display properly those
characters, so I have replaced them by »?«.
 
Java incorporated Unicode as a part of the language. Unicode
4, that is. Soon Java was invalidated by a new version of
Unicode. So, now in Java, a »char« is not a character
anymore, but just a part of a »surrogate pair«.
ram@zedat.fu-berlin.de (Stefan Ram): Apr 13 11:09AM

>used in real-life code? Is there anything in C++ standard
>that guarantees its validity and/or portability (at least to
>some extent) or is template metaprogramming merely a
 
The first metaprogram (1994 by Unruh) indeed gave its result
(a list of primes) as part of a /compiler error message/.
Martijn van Buul <pino@dohd.org>: Apr 13 07:39AM

* Victor Bazarov:
> in the above list of decimal digits shall be one greater than the value
> of the previous. "
 
> In my understanding it means that '1' == '0' + 1, and so on.
 
I stand corrected :)
 
 
 
--
Martijn van Buul - pino@dohd.org
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: