Saturday, April 4, 2015

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

SpreadTooThin <bjobrien62@gmail.com>: Apr 04 02:02PM -0700

I'm parsing a few million lines of log files and trying to sort things out.
 
My log files begin with stuff like:
 
2015-03-23 11:56:03,752
 
where 752, is milliseconds.
 
I have two log lines and I want to know (in milliseconds) what delta t is.
 
What std c++ object should I use and how do I get delta-t?
Ian Collins <ian-news@hotmail.com>: Apr 05 09:59AM +1200

SpreadTooThin wrote:
 
> where 752, is milliseconds.
 
> I have two log lines and I want to know (in milliseconds) what delta t is.
 
> What std c++ object should I use and how do I get delta-t?
 
Probably the most pragmatic approach is to read the timestamp, split the
result int milliseconds and the rest and then use your platform's native
date conversion functions or std::get_time to get a time in seconds.
 
--
Ian Collins
SpreadTooThin <bjobrien62@gmail.com>: Apr 04 04:02PM -0700

On Saturday, April 4, 2015 at 3:03:25 PM UTC-6, SpreadTooThin wrote:
 
> where 752, is milliseconds.
 
> I have two log lines and I want to know (in milliseconds) what delta t is.
 
> What std c++ object should I use and how do I get delta-t?
 
class logTime {

public:
void setTime(string s)
{
sscanf(s.c_str(), "%04d-%02d-%02d %02d:%02d:%02d,%d", &year, &month, &day, &hour, &minute, &second, &millisecond);
cout << "logTime" << year << "-" << month << "-" << day << " " << hour << ":" << minute << ":" << second << "," << millisecond << std::endl;
}
double deltaTinMS(logTime lt2)
{
time_t t2 = lt2.t1;
double deltaT;
deltaT = difftime(t2, t1);
deltaT = (deltaT * 1000) + lt2.millisecond - millisecond;
return deltaT;
}

private:
int year;
int month;
int day;
int hour;
int minute;
int second;
int millisecond;
std::time_t t1;
};
bleachbot <bleachbot@httrack.com>: Apr 04 09:46PM +0200

ram@zedat.fu-berlin.de (Stefan Ram): Apr 04 10:14PM

>2015-03-23 11:56:03,752
>I have two log lines and I want to know (in milliseconds) what delta t is.
 
You could use the I/O manipulator get_time from iomanip, but
it does not seem to support milliseconds. So, you still have
to parse the milliseconds manually. Then calculate the time
difference of the two "struct tm" using mktime and difftime
and then manually adjust for the two millisecond values.
 
Manually parsing a time looks like this:
 
#include <sstream>
#include <ctime>
 
...
 
::std::stringstream source{ "2015-03-23 11:56:03,752" };
int year; source >> year; source.get();
int month; source >> month; source.get();
int day; source >> day; source.get();
...
 
::std::tm tm0;
tm0->tm_year = year - 1900;
...
 
For Java, I wrote my one date-time library
»de.dclj.ram.system.gregorian« that already can parse split
seconds. I now report about this Java library:
 
Say, we would like to get the difference in seconds between
1784-02-14T02:29:21.574572+01:00 and
2108-08-16T05:49:31.346257+02:00 using a proleptic
astronomical calendar that does not take leap seconds into regard:
 
public class Main
{
public static void main( final java.lang.String[] args )
throws java.text.ParseException
{
final de.dclj.ram.system.gregorian.Instant instant =
new de.dclj.ram.notation.iso8601.Instant
( "1784-02-14T02:29:21.574572+01:00" ).getGregorian();
 
final de.dclj.ram.system.gregorian.Instant instant1 =
new de.dclj.ram.notation.iso8601.Instant
( "2108-08-16T05:49:31.346257+02:00" ).getGregorian();
 
java.lang.System.out.println
( instant1.bigFloatValue().minus( instant.bigFloatValue() )); }}
 
/* The output is:
 
10240309209.771685
 
*/
BV BV <bv8bv8bv8@gmail.com>: Apr 04 12:46PM -0700

Muhammad's Sword
 
 
Description: A Jewish atheist speaks about the notion that Islam spread by the sword.
 
Since the days when Roman Emperors threw Christians to the lions, the relations between the emperors and the heads of the church have undergone many changes.
 
Constantine the Great, who became Emperor in the year 306 - exactly 1700 years ago - encouraged the practice of Christianity in the empire, which included Palestine. Centuries later, the church split into an Eastern (Orthodox) and a Western (Catholic) part. In the West, the Bishop of Rome, who acquired the title of Pope, demanded that the Emperor accept his superiority.
 
The struggle between the Emperors and the Popes played a central role in European history and divided the peoples. It knew ups and downs. Some Emperors dismissed or expelled a Pope, some Popes dismissed or excommunicated an Emperor. One of the Emperors, Henry IV, "walked to Canossa", standing for three days barefoot in the snow in front of the Pope's castle, until the Pope deigned to annul his excommunication.
 
But there were times when Emperors and Popes lived in peace with each other. We are witnessing such a period today. Between the present Pope, Benedict XVI, and the present Emperor, George Bush II, there exists a wonderful harmony. Last week's speech by the Pope, which aroused a world-wide storm, went well with Bush's crusade against "Islamofascism", in the context of the "Clash of Civilizations".
 
In his lecture at a German university, the 265th Pope described what he sees as a huge difference between Christianity and Islam: while Christianity is based on reason, Islam denies it. While Christians see the logic of God's actions, Muslims deny that there is any such logic in the actions of Allah.
 
As a Jewish atheist, I do not intend to enter the fray of this debate. It is much beyond my humble abilities to understand the logic of the Pope. But I cannot overlook one passage, which concerns me too, as an Israeli living near the fault-line of this "war of civilizations".
 
In order to prove the lack of reason in Islam, the Pope asserts that the prophet Muhammad ordered his followers to spread their religion by the sword. According to the Pope, that is unreasonable, because faith is born of the soul, not of the body. How can the sword influence the soul?
 
To support his case, the Pope quoted - of all people - a Byzantine Emperor, who belonged, of course, to the competing Eastern Church. At the end of the 14th century, the Emperor Manuel II Palaeologus told of a debate he had - or so he said (its occurrence is in doubt) - with an unnamed Persian Muslim scholar. In the heat of the argument, the Emperor (according to himself) flung the following words at his adversary:
 
"Show me just what Mohammed brought that was new, and there you will find things only evil and inhuman, such as his command to spread by the sword the faith he preached".
 
These words give rise to three questions: (a) Why did the Emperor say them? (b) Are they true? (c) Why did the present Pope quote them?
 
WHEN MANUEL II wrote his treatise, he was the head of a dying empire. He assumed power in 1391, when only a few provinces of the once illustrious empire remained. These, too, were already under Turkish threat.
 
At that point in time, the Ottoman Turks had reached the banks of the Danube. They had conquered Bulgaria and the north of Greece, and had twice defeated relieving armies sent by Europe to save the Eastern Empire. On May 29, 1453, only a few years after Manuel's death, his capital, Constantinople (the present Istanbul) fell to the Turks, putting an end to the Empire that had lasted for more than a thousand years.
 
During his reign, Manuel made the rounds of the capitals of Europe in an attempt to drum up support. He promised to reunite the church. There is no doubt that he wrote his religious treatise in order to incite the Christian countries against the Turks and convince them to start a new crusade. The aim was practical, theology was serving politics.
 
In this sense, the quote serves exactly the requirements of the present Emperor, George Bush II. He, too, wants to unite the Christian world against the mainly Muslim "Axis of Evil". Moreover, the Turks are again knocking on the doors of Europe, this time peacefully. It is well known that the Pope supports the forces that object to the entry of Turkey into the European Union.
 
Is there any truth in Manuel's argument
 
 
 
The pope himself threw in a word of caution. As a serious and renowned theologian, he could not afford to falsify written texts. Therefore, he admitted that the Quran specifically forbade the spreading of the faith by force. He quoted the second Sura, verse 256 (strangely fallible, for a pope, he meant verse 257) which says:
 
"There must be no coercion in matters of faith."
 
How can one ignore such an unequivocal statement? The Pope simply argues that this commandment was laid down by the prophet when he was at the beginning of his career, still weak and powerless, but that later on he ordered the use of the sword in the service of the faith. Such an order does not exist in the Quran. True, Muhammad called for the use of the sword in his war against opposing tribes - Christian, Jewish and others - in Arabia, when he was building his state. But that was a political act, not a religious one; basically a fight for territory, not for the spreading of the faith.
 
Jesus said: "You will recognize them by their fruits." The treatment of other religions by Islam must be judged by a simple test: How did the Muslim rulers behave for more than a thousand years, when they had the power to "spread the faith by the sword"?
 
Well, they just did not.
 
For many centuries, the Muslims ruled Greece. Did the Greeks become Muslims? Did anyone even try to Islamize them? On the contrary, Christian Greeks held the highest positions in the Ottoman administration. The Bulgarians, Serbs, Romanians, Hungarians and other European nations lived at one time or another under Ottoman rule and clung to their Christian faith. Nobody compelled them to become Muslims and all of them remained devoutly Christian.
 
True, the Albanians did convert to Islam, and so did the Bosniaks. But nobody argues that they did this under duress. They adopted Islam in order to become favorites of the government and enjoy the fruits.
 
In 1099, the Crusaders conquered Jerusalem and massacred its Muslim and Jewish inhabitants indiscriminately, in the name of the gentle Jesus. At that time, 400 years into the occupation of Palestine by the Muslims, Christians were still the majority in the country. Throughout this long period, no effort was made to impose Islam on them. Only after the expulsion of the Crusaders from the country, did the majority of the inhabitants start to adopt the Arabic language and the Muslim faith - and they were the forefathers of most of today's Palestinians.
 
There is no evidence whatsoever of any attempt to impose Islam on the Jews. As is well known, under Muslim rule the Jews of Spain enjoyed a bloom the like of which the Jews did not enjoy anywhere else until almost our time. Poets like Yehuda Halevy wrote in Arabic, as did the great Maimonides. In Muslim Spain, Jews were ministers, poets, scientists. In Muslim Toledo, Christian, Jewish and Muslim scholars worked together and translated the ancient Greek philosophical and scientific texts. That was, indeed, the Golden Age. How would this have been possible, had the Prophet decreed the "spreading of the faith by the sword"?
 
What happened afterwards is even more telling. When the Catholics re-conquered Spain from the Muslims, they instituted a reign of religious terror. The Jews and the Muslims were presented with a cruel choice: to become Christians, to be massacred or to leave. And where did the hundreds of thousand of Jews, who refused to abandon their faith, escape? Almost all of them were received with open arms in the Muslim countries. The Sephardi ("Spanish") Jews settled all over the Muslim world, from Morocco in the west to Iraq in the east, from Bulgaria (then part of the Ottoman Empire) in the north to Sudan in the south. Nowhere were they persecuted. They knew nothing like the tortures of the Inquisition, the flames of the auto-da-fe, the pogroms, the terrible mass-expulsions that took place in almost all Christian countries, up to the Holocaust.
 
Why? Because Islam expressly prohibited any persecution of the "peoples of the book"[1]. In Islamic society, a special place was reserved for Jews and Christians. They did not enjoy completely equal rights, but almost. They had to pay a special poll-tax, but were exempted from military service - a trade-off that was quite welcome to many Jews. It has been said that Muslim rulers frowned upon any attempt to convert Jews to Islam even by gentle persuasion - because it entailed the loss of taxes[2].
 
Every honest Jew who knows the history of his people cannot but feel a deep sense of gratitude to Islam, which has protected the Jews for fifty generations, while the Christian world persecuted the Jews and tried many times "by the sword" to get them to abandon their faith.
 
The story about "spreading the faith by the sword" is an evil legend, one of the myths that grew up in Europe during the great wars against the Muslims - the reconquista of Spain by the Christians, the Crusades and the repulsion of the Turks, who almost conquered Vienna. I suspect that the German Pope, too, honestly believes in these fables. That means that the leader of the Catholic world, who is a Christian theologian in his own right, did not make the effort to study the history of other religions.
 
Why did he utter these words in public? And why now?
 
There is no escape from viewing them against the background of the new Crusade of Bush and his evangelist supporters, with his slogans of "Islamofascism" and the "Global War on Terrorism" - when "terrorism" has become a synonym for Muslims. For Bush's handlers, this is a cynical attempt to justify the domination of the world's oil resources. Not for the first time in history, a religious robe is spread to cover the nakedness of economic interests; not for the first time, a robbers' expedition becomes a Crusade.
 
The speech of the Pope blends into this effort. Who can foretell the dire consequences
 
 
 
http://www.islamreligion.com/articles/513/viewall/
 
 
 
Thank you
Melzzzzz <mel@zzzzz.com>: Apr 04 05:59AM +0200

That is my conclusion.
With C++11 & 14, I can't see any new language that can replace it.
 
My considerations:
 
1. rust:
- Compiling of compiler does take very long time because it compiles
libraries as single source and therefore does not utilize multiple
cores
- doing simple things require unsafe blocks and ugly unsafe code
eg:
/// Pop a mutable reference off the head of a slice, mutating the slice
to no
 
/// longer contain the mutable reference. This is a safe operation
because the
 
/// two mutable borrows are entirely disjoint.
 
fn shift_mut_ref<'a, T>(r: &mut &'a mut [T]) -> Option<&'a mut T> {
 
use std::mem;
 
use std::raw::Repr;
 
 
 
if r.len() == 0 { return None }
 
unsafe {
 
let mut raw = r.repr();
 
let ret = raw.data as *mut T;
 
raw.data = raw.data.offset(1);
 
raw.len -= 1;
 
*r = mem::transmute(raw);
 
Some({ &mut *ret })
 
}
 
}
 
http://benchmarksgame.alioth.debian.org/u64q/program.php?test=nbody&lang=rust&id=1
I don;t think this requires comments...
 
2. go
- does not have templates, therefore there are tools to generate code
from templates which is so 90es...
- optimizer is in infant stage.
- calls through interfaces are slow
- calls to external libs are very costly (this is remedied in gccgo,
but than code isn't portable to standard go compiler)
- only good for server side programming that does not have heavy numeric
processing, because of slow code.
- java bits it hands down
+ could replace python, but no more
+ extremely fast compilation
 
3. nim
- one man project
- small user base
- python/pascal syntax with indentation instead of {}
- buggy
+ compiles to c/c++ and obj c even java script
+ templates and very innovative macros.
+ multi methods
+ supports both GC and manual memory management
- not nearly as good as C++ , yet, but promising
 
That's runt for now ;)
woodbrian77@gmail.com: Apr 03 10:47PM -0700

On Friday, April 3, 2015 at 10:59:36 PM UTC-5, Melzzzzz wrote:
 
> 2. go
> - does not have templates, therefore there are tools to generate code
> from templates which is so 90es...
 
I think it's hip, but I'm working on something similar.
 
> - java bits it hands down
> + could replace python, but no more
> + extremely fast compilation
 
I don't think Go will be able to put much of a dent in C++.
 
> - python/pascal syntax with indentation instead of {}
> - buggy
> + compiles to c/c++ and obj c even java script
 
Why do you consider that to be a plus? It might be
too many languages.
 
> + multi methods
> + supports both GC and manual memory management
> - not nearly as good as C++ , yet, but promising
 
What language is the Nim compiler written in? I saw
something on Wikipedia about it being written in Pascal.
That might be considered a weakness.
 
Happy Passover. Happy Holy Week.
 
Brian
Ebenezer Enterprises
http://webEbenezer.net
Melzzzzz <mel@zzzzz.com>: Apr 04 07:58AM +0200

On Fri, 3 Apr 2015 22:47:27 -0700 (PDT)
> > + compiles to c/c++ and obj c even java script
 
> Why do you consider that to be a plus? It might be
> too many languages.
 
It mixes nicely eg if you write C++ as it generates C++ files.
One other thing I forgot to mention it only requires libc
and C compiler in order to be compiled.
 
> > - not nearly as good as C++ , yet, but promising
 
> What language is the Nim compiler written in? I saw
> something on Wikipedia about it being written in Pascal.
 
Hm, no, it is written in Nim as I see sources.
 
> That might be considered a weakness.
 
> Happy Passover. Happy Holy Week.
 
Same to you ;)
red floyd <no.spam.here@its.invalid>: Apr 04 12:05PM -0700

On 4/3/2015 8:59 PM, Melzzzzz wrote:
> With C++11 & 14, I can't see any new language that can replace it.
 
> My considerations:
 
> 1. rust:
 
The other problem is, of course, you can't pause your program
for a specified time, because as we all know, "Rust Never Sleeps"
"Öö Tiib" <ootiib@hot.ee>: Apr 03 04:35PM -0700

On Saturday, 4 April 2015 01:58:56 UTC+3, Stefan Ram wrote:
> an equivalent piece of C++ and said that the C++ was
> not very much longer. I just now become aware of the
> fact that he omitted the »#include«s from the C++ code!
 
 
Including <iostream> is guaranteed to include also <ios>,
<streambuf>, <istream>, <ostream> and <iosfwd>.
 
So you actually needed <iostream> and <iomanip>
 
 
> In the case of »printf« the »%6.1f« /always/ only refers to
> a single output operation and the include /always/ is
> »#include <cstdio>«.
 
Yeah, using the C++ I/O manipulators a lot is somewhat annoying.
 
> system, so that we have a standard to express semantic
> requirements for the operations of a concept. Like, for
> example, a kind of Doxygen becoming part of ISO C++.
 
We will see. I suspect we maybe hope too lot from those long
promised things like concepts, reflection or modules.
Bo Persson <bop@gmb.dk>: Apr 04 10:54AM +0200

On 2015-04-04 00:58, Stefan Ram wrote:
 
> In the case of »printf« the »%6.1f« /always/ only refers to
> a single output operation and the include /always/ is
> »#include <cstdio>«.
 
On the other hand, printf fails totally and miserably for user defined
types.
"Öö Tiib" <ootiib@hot.ee>: Apr 04 04:31AM -0700

On Saturday, 4 April 2015 11:54:42 UTC+3, Bo Persson wrote:
> > »#include <cstdio>«.
 
> On the other hand, printf fails totally and miserably for user defined
> types.
 
Overload of 'std::ostream& operator<<(std::ostream&, Type const&)'
is pointless for 'printf' indeed. OTOH lot of text output goes not
to streams (for example to GUI) and so some form of 'to_string' is
even more likely than 'operator<<' overload.
 
All those standalone 'to_string' and member 'toString' may be used
like they are used with 'cout':
 
some_space::UserType variable = getItFromSomeWhere();
 
// cout
std::cout << "variable is " << to_string(variable) << "\n";
 
// printf
printf( "variable is %s\n", to_string(variable).c_str() );
 
 
It is matter of taste definitely but not exactly total and
miserable failure. May be I do not see some aspect of it clearly?
woodbrian77@gmail.com: Apr 03 06:20PM -0700

On Friday, April 3, 2015 at 8:12:03 AM UTC-5, Öö Tiib wrote:
> On Thursday, 2 April 2015 07:51:11 UTC+3, woodb...@gmail.com wrote:
> > What do you think of this class?
 
> Average class.
 
Here's an updated version
 
class failure : public ::std::exception {
::std::string whatStr;
 
public:
explicit failure (char const* w) : whatStr(w) {}
explicit failure (::std::string w) : whatStr(::std::move(w)) {}
 
char const* what () const throw()
{ return whatStr.c_str(); }
 
failure& operator<< (char const* s)
{
whatStr.append(s);
return *this;
}
 
failure& operator<< (char* s)
{
whatStr.append(s);
return *this;
}
 
failure& operator<< (::std::string const& s)
{
whatStr.append(s);
return *this;
}
 
template <class T>
failure& operator<< (T val)
{
using ::std::to_string;
return *this << to_string(val);
}
};
 
 
I took your advice and removed the destructor and added
the using statement. I'm not sure what the advantage
would be to changing that signature from char const* to
char const [] so I didn't change that.
 
 
 
> > ~failure () throw() {}
 
> Feels pointless to indicate 'noexcept' here since compiler can see it
> itself.
 
I don't think of programs as selves. I'd compare a compiler
to a rock or a shovel.
 
> > return *this;
> > }
 
> That looks unneeded overload; its body is identical to previous overload.
 
It looks that way to me too, but I've not been able to
get rid of it. If I remove it, the compiler chooses
between the char const* and the templated operator<<.
Rather than picking the char const* version, it picks
the templated version and then gives errors. Previously
on the newsgroup I mentioned this and someone suggested
using enable_if, but I wasn't crazy about that idea.
 

> strange byte sequence did not let a parser to parse the input,
> then do not build such thing at throw site and executable size is
> immediately smaller too.
 
That seems to be easier said than done. I'm not sure who
does that.
 
Brian
Ebenezer Enterprises - In G-d we trust.
http://webEbenezer.net
"Öö Tiib" <ootiib@hot.ee>: Apr 04 03:19AM -0700

> the using statement. I'm not sure what the advantage
> would be to changing that signature from char const* to
> char const [] so I didn't change that.
 
I wrote what I have seen some coding standards suggesting.
I am also not always sure about advantage, it is often just
syntax that some people consider easier to read, others not.
 
Sometimes there is practical value too. For example to
indicating 'override' consistently helps when someone changes
a base class virtual and forgets to update one of overrides.
It is then compile error since it does not override anything
anymore.
 
...
 
> I don't think of programs as selves. I'd compare a compiler
> to a rock or a shovel.
 
Software is more active than rock or shovel. It does sometimes rather
complex things on its own among other things. C++ code is text with
complex rules of interpretation so sometimes one may have to rearrange
it a bit to make it easier to parse for certain tools and people.
 
...
 
> > immediately smaller too.
 
> That seems to be easier said than done. I'm not sure who
> does that.
 
What is 'that'? I would call your second version of 'failure' as
'string_builder'. It extended 'std::string' to make building
texts more convenient. That is why I suspected that may be you
build complex texts with it and maybe those texts are not really
useful.
 
We sometimes build complex texts for logging or tracing but it
is orthogonal to exceptions. Lot of logs and traces are only
temporary for debugging/testing and so removed or turned off
from end products but exceptions are functional part of behavior
and remain same.
 
Exceptions need to have sufficient variety of types so
catch site can catch 'my::FileNotFound', 'my::AccessDenied' and
'my::BadDataInFile' separately when there is difference in
handling or just 'std::exception' base class when there are
no difference in handling.
Melzzzzz <mel@zzzzz.com>: Apr 04 05:07AM +0200

On Thu, 2 Apr 2015 20:32:57 -0700 (PDT)
 
> Given that key is a string and the element that it represents is a
> vector of strings:
 
> How do I add an element to myMap?
 
myMap["abc"].push_back(newstring);
 
> myvect = map[key];
> *myvect->push_back(newstring);
 
> Shouldn't I be using a refrence to an object rather than a pointer?
 
you can get reference:
std::vector<string>& abc = myMap["abc"];
no copying involved,
 
 
PS:
 
Why do you use map? unordered_map should now be prefered, that is, you
need map, only if you want ordered access.
Melzzzzz <mel@zzzzz.com>: Apr 04 04:58AM +0200

On Fri, 03 Apr 2015 14:07:35 +0200
> https://github.com/unimock-cpp/unimock/wiki
 
> Thanks!
> Daniel
 
I can't figure out what to do with it....
Melzzzzz <mel@zzzzz.com>: Apr 04 04:54AM +0200

On Fri, 3 Apr 2015 06:00:24 -0700 (PDT)
 
> I'm going to upload text file using c++. I'm using this code but this
> is not working and there is no error in this code. can you give me
> suggestion why this is not working? Here is code.
 
I guess you have to read file and send it, no?
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: