Monday, August 8, 2016

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

MikeCopeland <mrc2323@cox.net>: Aug 07 06:13PM -0700

Given: a value of 17234987, is there a (good) way to format it for
output as 17,234,987? I would have thought that stream i/o would
support such formatting, but I can't find anything that seems to show
how to do it.
Please advise. TIA
 
 
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
"Öö Tiib" <ootiib@hot.ee>: Aug 07 06:31PM -0700

On Monday, 8 August 2016 04:14:09 UTC+3, MikeCopeland wrote:
> support such formatting, but I can't find anything that seems to show
> how to do it.
> Please advise. TIA
 
You have to use 'std::locale' and 'std::put_money' read up on those
for details. Teaser example:
 
#include <iostream> // for std::cout
#include <iomanip> // std::put_money and other utilities

int main(int argc, char **argv)
{
const int amount = 1000000; // in cents

std::cout.imbue(std::locale("en_US.UTF-8"));

std::cout << std::showbase << std::put_money(amount) << '\n';
}
 
That should output ...
 
$10,000.00
MikeCopeland <mrc2323@cox.net>: Aug 07 08:36PM -0700

> }
 
> That should output ...
 
> $10,000.00
 
Not quite wqhat I'm looking for: I'm not working with money data, but
large integer values. With your solution, there's no way to format
integers >999 with punctuation. Am I missing something?
 
 
 
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
"Öö Tiib" <ootiib@hot.ee>: Aug 08 12:24AM -0700

On Monday, 8 August 2016 06:36:26 UTC+3, MikeCopeland wrote:
 
> Not quite wqhat I'm looking for: I'm not working with money data, but
> large integer values. With your solution, there's no way to format
> integers >999 with punctuation. Am I missing something?
 
Indeed, you missed my remark that it was example and my suggestion to read
up on the things involved. You hate to read? OK I will complete it
for you:
 
#include <iostream> // for std::cout
#include <iomanip> // std::put_money and other utilities

int main(int argc, char **argv)
{
const int amount = 17234987; // in cents

std::cout.imbue(std::locale("ja_JP.UTF-8"));

std::cout << std::put_money(amount) << '\n';
}
 
Done, 17,234,987 exactly as specified. Was it that hard?
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Aug 08 10:56AM +0200

On 08.08.2016 03:31, Öö Tiib wrote:
> }
 
> That should output ...
 
> $10,000.00
 
UTF-8 for byte streams is not supported in Windows.
 
So that's very non-portable code. ;-)
 
Also, consider `num_put`. Mike's example indicates that it's just a
number, not a monetary amount.
 
 
Cheers!,
 
- Alf
"Öö Tiib" <ootiib@hot.ee>: Aug 08 06:54AM -0700

On Monday, 8 August 2016 11:56:39 UTC+3, Alf P. Steinbach wrote:
 
> > $10,000.00
 
> UTF-8 for byte streams is not supported in Windows.
 
> So that's very non-portable code. ;-)
 
UTF-8 is right now 83% - 87% of all web content ... so if Windows
can't even byte stream that then what is it useful for? Perhaps
something like "English_Australia.1252" will work there then. :-)
 
 
> Also, consider `num_put`. Mike's example indicates that it's just a
> number, not a monetary amount.
 
Perhaps 'num_put' is indeed best. I wondered how he can't find
*anything* in stream I/O and so I just pointed direction. If he
wants to use I/O utilities then he has quite lot to read there.
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Aug 08 07:33AM -0700

On Sunday, August 7, 2016 at 9:14:09 PM UTC-4, MikeCopeland wrote:
> support such formatting, but I can't find anything that seems to show
> how to do it.
> Please advise. TIA
 
auto amt1 = amount % 1000;
auto amt2 = (amount % 1000000) / 1000;
auto amt3 = (amount % 1000000000) / 1000000;

if (amount < 1000)
cout << amt1;
else if (amount < 1000000)
cout << amt2 << "," << amt1;
else if (amount < 1000000000)
cout << amt3 << "," << amt2 << "," << amt1;
 
Something like that.
 
Best regards,
Rick C. Hodgin
scott@slp53.sl.home (Scott Lurndal): Aug 08 02:48PM

>support such formatting, but I can't find anything that seems to show
>how to do it.
> Please advise. TIA
 
Use 'snprintf'. The ' formatting flag will use the grouping
character from the locale to group digits appropriately.
 
http://pubs.opengroup.org/onlinepubs/7908799/xsh/fprintf.html
"Öö Tiib" <ootiib@hot.ee>: Aug 08 07:54AM -0700

On Monday, 8 August 2016 17:33:30 UTC+3, Rick C. Hodgin wrote:
> else if (amount < 1000000000)
> cout << amt3 << "," << amt2 << "," << amt1;
 
> Something like that.
 
*Bzzzzt*, wrong, but thank you for playing.
What it will output on case of amount = 17004087?
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Aug 08 07:59AM -0700

On Monday, August 8, 2016 at 10:33:30 AM UTC-4, Rick C. Hodgin wrote:
> else if (amount < 1000000000)
> cout << amt3 << "," << amt2 << "," << amt1;
 
> Something like that.
 
I don't know how in C++ to make it work with values < 100 the lower
amounts. It will produce weird things like "1,23,456" for 1,023,456".
I'd have to use what I know. :-)
 
int amount = 1023045;
char buf1[4], buf2[4];
sprintf(buf1, "%03d", amount % 1000);
sprintf(buf2, "%03d", (amount % 1000000) / 1000);
auto amt1 = amount % 1000;
auto amt2 = (amount % 1000000) / 1000;
auto amt3 = (amount % 1000000000) / 1000000;
 
if (amount < 1000)
cout << amt1;
else if (amount < 1000000)
cout << amt2 << "," << buf1;
else if (amount < 1000000000)
cout << amt3 << "," << buf2 << "," << buf1;
 
Best regards,
Rick C. Hodgin
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Aug 08 08:00AM -0700

On Monday, August 8, 2016 at 10:55:21 AM UTC-4, Öö Tiib wrote:
> > cout << amt3 << "," << amt2 << "," << amt1;
 
> > Something like that.
 
> *Bzzzzt*, wrong, but thank you for playing.
 
I appreciate your kindness in pointing out my mistake. It reveals much
about your character.
 
> What it will output on case of amount = 17004087?
 
17,4,87.
 
Best regards,
Rick C. Hodgin
woodbrian77@gmail.com: Aug 07 10:42PM -0700

http://stackoverflow.com/questions/38786210/deserialize-data-on-the-fly-from-stream-or-file
 
I was looking at an answer to the question there. The guy
suggests using Protocol Buffers saying:
 
1 It can be used on wire (TCP etc.)
2 Simple grammar to write the .proto file for composing your own messages
3 Cross platform & available with multiple languages
4 Very efficient compared to JSON & XML
5 Generates header & source files for handy getter, setter, serialize, deserialize & debugging purpose
 
I'll go through the above items and talk about how they
compare to the C++ Middleware Writer (CMW).
 
1 CMW code can also be used with network protocols.
2 The CMW also has a simple grammar but has "middle"
files rather than .proto files.
 
3 The CMW supports multiple platforms, but it doesn't
support multiple languages. G-d willing, in the future,
we will support more languages.
 
4 Should be much more efficient than either JSON or XML, but
I don't have any numbers.
5 Generates headers (only) for serialization/messaging purposes.
 
The CMW, unlike Protocol Buffers, is an on line code generator.
There are a number of advantages to that:
 
"Middleware-as-a-service" will continue to disrupt the market
for traditional middleware in 2016
 
http://www.reseller.co.nz/article/590705/middleware-as-a-service-turns-enterprise-integration-its-head/
 
---------------------------------------------------
 
"The advantage is that the consumer can quickly be up
and running using the SaaS solution and does not have
to manage and maintain the application freeing up
precious IT resources to work on other priorities.
 
Another advantage is that the SaaS provider keeps up
with changes in technology so that the consumer does
not have to."
 
http://www.techradar.com/us/news/internet/cloud-services/mike-kavis-architecting-a-cloud-1214419/2
 
----------------------------------------------------
 
Beyond those technical advantages, there's also the
joy of knowing that your business model is able to
serve an increasingly lawless/chaotic world. Ebenezer
Enterprises is increasingly lawful and orderly, but we
are an exception to the rule. The US used to be a
force for law and order, but, partly due to weak
leadership in the Oval Office (Clinton, Bushes, Obama),
we aren't as strong on that as we used to be. So like
Europe and other places, we are paying a heavy price --
an ounce of prevention is worth more than a pound of cure.
 
Brian
Ebenezer Enterprises - In G-d we trust.
http://webEbenezer.net
woodbrian77@gmail.com: Aug 07 11:14PM -0700

> serve an increasingly lawless/chaotic world. Ebenezer
> Enterprises is increasingly lawful and orderly, but we
> are an exception to the rule.
 
This song talks about being protected in the eye
of the storm.
 
https://duckduckgo.com/?q=in+the+eye+of+the+storm+ryan+stevenson&t=h_&ia=videos&iai=-sx8wTnnfSc
Ian Collins <ian-news@hotmail.com>: Aug 08 06:27PM +1200

On 08/ 8/16 05:42 PM, woodbrian77@gmail.com wrote:
 
<snip>
> The CMW, unlike Protocol Buffers, is an on line code generator.
 
Which would prevent it's use on any of the projects I'm currently
working with.
 
--
Ian
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Aug 08 10:58AM +0200

On 08.08.2016 08:27, Ian Collins wrote:
>> The CMW, unlike Protocol Buffers, is an on line code generator.
 
> Which would prevent it's use on any of the projects I'm currently
> working with.
 
Hey, it's its, not it's.
 
Cheers!,
 
- Alf
jacobnavia <jacob@jacob.remcomp.fr>: Aug 08 01:30PM +0200

Le 08/08/2016 à 10:58, Alf P. Steinbach a écrit :
 
> Hey, it's its, not it's.
 
> Cheers!,
 
> - Alf
 
care to explain for the english impaired?
 
Jacob
 
Paris, France
Daniel <danielaparker@gmail.com>: Aug 08 04:53AM -0700


> This song talks about being protected in the eye
> of the storm.
 
This song talks about what happens to Middleware writers who don't thinks it's
necessary to follow de facto standards for serialization/deserialization.
 
https://www.youtube.com/watch?v=ue2-ZVxpVjc
Ben Bacarisse <ben.usenet@bsb.me.uk>: Aug 08 01:48PM +0100


>>> Which would prevent it's use on any of the projects I'm currently
>>> working with.
 
>> Hey, it's its, not it's.
<snip>
> care to explain for the english impaired?
 
"It's" is a contraction of "it is" or "it has" ("it's been ages since we
spoke", "it's to hot out there"). "Its" is a possessive pronoun like
his and yours. Many of these have an 's' at the end, but none have an
apostrophe.
 
When you write "it's" replace it with "it is" to see if that's what you
want. To check if "its" is right, try using "their" or "his" in its
place. The sentence won't make sense, but it will have the right shape.
 
--
Ben.
"Fred.Zwarts" <F.Zwarts@KVI.nl>: Aug 08 02:54PM +0200

"jacobnavia" schreef in bericht news:no9qg6$g6j$1@dont-email.me...
 
>care to explain for the english impaired?
 
>Jacob
 
>Paris, France
 
It's about spelling and the difference between "its" and "it's", where
"it's" is short for "it is", whereas "its" must be followed by a noun, which
is roughly the same as the noun followed by "of it". "In the sentence above,
"it's use" should be "its use", because one could say "use of it", not "it
is use". It is a somewhat strange rule, because this is the (almost?) only
exception to the rule that a genitive is expressed with "apostophe s" in
English. So, the error is understandable.
jacobnavia <jacob@jacob.remcomp.fr>: Aug 08 02:55PM +0200

Le 08/08/2016 à 14:48, Ben Bacarisse a écrit :
 
> When you write "it's" replace it with "it is" to see if that's what you
> want. To check if "its" is right, try using "their" or "his" in its
> place. The sentence won't make sense, but it will have the right shape.
 
Thanks Ben
jacobnavia <jacob@jacob.remcomp.fr>: Aug 08 02:55PM +0200

Le 08/08/2016 à 14:54, Fred.Zwarts a écrit :
> "use of it", not "it is use". It is a somewhat strange rule, because
> this is the (almost?) only exception to the rule that a genitive is
> expressed with "apostophe s" in English. So, the error is understandable.
 
 
Thanks
David Brown <david.brown@hesbynett.no>: Aug 08 02:57PM +0200

On 08/08/16 13:30, jacobnavia wrote:
 
>> Cheers!,
 
>> - Alf
 
> care to explain for the english impaired?
 
Your English is too good to call it "impaired", but I can explain anyway.
 
"it's" is an abbreviation for "it is". "its" is the possessive pronoun.
Thus:
 
It's a nice day.
The dog caught its ball.
 
Ian had used "it's", when he should have used "its".
 
It's common to get these mixed up sometimes, even for native speakers.
Daniel <danielaparker@gmail.com>: Aug 08 06:08AM -0700

On Monday, August 8, 2016 at 4:58:32 AM UTC-4, Alf P. Steinbach wrote:
 
> > Which would prevent it's use on any of the projects I'm currently
> > working with.
 
> Hey, it's its, not it's.
 
Right, so SFINAE implies it _is_ suitable for the projects he's currently working on.
 
Daniel
"Öö Tiib" <ootiib@hot.ee>: Aug 07 06:16PM -0700

On Monday, 8 August 2016 01:10:52 UTC+3, Daniel wrote:
> A<std::string> a("key","value");
> A<std::string>::value_type& data = a.data();
> }
 
 
There are some implicit conversions between pairs that differ by
constness of elements. Those convenience implicit conversions can
actually be invisible and non-obvious source of inefficiency when
dealing with 'std::map' for example.
 
However what you do is outright wrong I believe. The classes
'std::pair<std::string const, std::string>' and 'std::pair<std::string,
std::string>' are still different classes and 'reinterpret_cast' between
references to such different classes is not guaranteed to work.
Daniel <danielaparker@gmail.com>: Aug 07 08:09PM -0700

On Sunday, August 7, 2016 at 9:16:36 PM UTC-4, Öö Tiib wrote:
> 'std::pair<std::string const, std::string>' and 'std::pair<std::string,
> std::string>' are still different classes and 'reinterpret_cast' between
> references to such different classes is not guaranteed to work.
 
Thanks,
Daniel
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: