Tuesday, May 5, 2015

Digest for comp.lang.c++@googlegroups.com - 17 updates in 7 topics

ram@zedat.fu-berlin.de (Stefan Ram): May 05 06:48PM

>, then »"a"s + "b"s« is a temporary, so it does not have to
>be copied from but can be moved from. Is this guaranteed to
>happen? Is there a name for this "optimization" (akin to "RVO")?
 
It's possibly called »copy elision«.
bleachbot <bleachbot@httrack.com>: May 05 10:19PM +0200

ram@zedat.fu-berlin.de (Stefan Ram): May 05 10:12PM

>Is it possible to define operator operator[][]?
 
It can be demonstrated by a one-liner (80 characters):
 
struct s{ s & operator[]( int ){ return *this; }}; int main(){ s{}[ 0 ][ 0 ]; }
 
.
ram@zedat.fu-berlin.de (Stefan Ram): May 05 10:57PM

>What does it mean s{}?
 
In this case, it means, "an instance of s".
It is a functional notation type conversion (5.2.3)
[expr.type.conv].
asetofsymbols@gmail.com: May 05 03:00PM -0700

Is it possible to define operator operator[][]?
(and operator[][][] and operator[][][][])
 
T& operator[](int i)
{}
Seems the only that compile
red floyd <no.spam@its.invalid>: May 05 03:12PM -0700


> T& operator[](int i)
> {}
> Seems the only that compile
 
Only if T is either a pointer, array, or some type that has operator[]()
defined.
asetofsymbols@gmail.com: May 05 03:24PM -0700

Stefan wrote:
<< it
can be demonstrated by a one-liner (80 characters):
 
struct s{ s & operator[]( int ){ return *this; }}; int main(){ s{}[ 0 ][ 0 ]; }
 
What does it mean s{}?
 
I think i can easily resolve this
call as function M.elm(i, j)
at place of M[i][j]...
BV BV <bv8bv8bv8@gmail.com>: May 05 01:19PM -0700

Why Islam is the true religion of God.
 
Ever since the dawn of mankind, we have sought to understand nature and our place in it. In this quest for the purpose of life many people have turned to religion. Most religions are based on books claimed by their followers to be divinely inspired, without any proof. Islam is different because it is based upon reason and proof.
There are clear signs that the book of Islam, the Quran, is the word of God and we have many reasons to support this claim:
· There are scientific and historical facts found in the Quran which were unknown to the people at the time, and have only been discovered recently by contemporary science.
· The Quran is in a unique style of language that cannot be replicated, this is known as the 'Inimitability of the Quran.'
· There are prophecies made in the Quran and by the Prophet Muhammad, may the mercy and blessings of God be upon him, which have come to be pass.
This article lays out and explains the scientific facts that are found in the Quran, centuries before they were 'discovered' in contemporary science. It is important to note that the Quran is not a book of science but a book of 'signs'. These signs are there for people to recognise God's existence and affirm His revelation. As we know, science sometimes takes a 'U-turn' where what once scientifically correct is false a few years later. In this article only established scientific facts are considered, not just theories or hypothesis.
 
Scientific Facts in the Quran
 
The Quran was revealed to the Prophet Muhammad in the 7th century.
Science at the time was primitive, there were no telescopes, microscopes or anything even close to the technology we have today. People believed that the sun orbited the earth and that the sky was held up by big pillars at the corners of a flat earth. Within this backdrop the Quran was revealed, and it contains many scientific facts on topics ranging from astronomy to biology, geology to sociology.
Some people may claim that the Quran was changed as new scientific facts were discovered but this cannot be the case because it is a historically documented fact that the Quran is preserved in its original language[1]. The Quran was written down and memorised by people during the lifetime of the Prophet Muhammad. One of the copies of the Quran which was written a few years after the death of the Prophet Muhammad is preserved in a museum in Uzbekistan. This copy is over 1400 years old and is exactly the same as the Arabic Quran that we have today[2].
The following are nine scientific facts found in the Quran:
 
1. Origin of Life
 
Water is essential for all living things. We all know that water is vital to life but the Quran makes a very unusual claim:
We made every living thing from water? Will they not believe? (Quran 21:30)
In this verse water is pointed out as the origin of all life. All living things are made of cells. We now know that cells are mostly made up of water[3]. For example, 80% of the cytoplasm (basic cell material) of a standard animal cell is described as water in biology textbooks.
The fact that living things consist mostly of water was discovered only after the invention of the microscope. In the deserts of Arabia, the last thing someone would have guessed is that all life came from water.
 
2. Iron
 
Iron is not natural to the earth. It did not form on the earth but came down to earth from outer space. This may sound strange but it's true. Scientists have found that billions of years ago the earth was stuck by meteorites. These meteorites were carrying Iron from distant stars which had exploded[4].
The Quran says the following on the origin of Iron:
"We sent down Iron with its great inherent strength and its many benefits for humankind." (Quran 57:25)
God uses the words 'sent down' for Iron. It is clear from the verse that Iron is not an earthly material, but was sent down for the benefit of humanity. The fact that Iron came down to earth from outer space is something which could not be known by the primitive science of the 7th century.
 
3. Sky's Protection
 
The sky plays a crucial role in protecting the earth. The sky protects the earth from the lethal rays of the sun. If the sky did not exist then the sun's radiation would have killed off all life on earth. It also acts like a blanket wrapped around the earth, to protect it from the freezing cold of space. The temperature just above the sky is approximately -270oC. If this temperature was to reach earth then the planet would freeze over instantly. The sky also protects life on earth by warming the surface through heat retention (greenhouse effect), and reducing temperature extremes between day and night[5]. These are some of the many protective functions of the sky.
The Quran asks us to consider the sky in the following verse:
"We made the sky a protective ceiling. And yet they are turning away from Our signs!" (Quran 21:32)
The Quran points to the sky's protection as a sign of God. The protective properties of the sky were discovered by scientific research conducted in the 20th century.
 
4. Mountains
 
The Quran draws our attention to a very important characteristic of mountains:
"Did We not make the earth a resting place? And the mountains as stakes?" (Quran 78:6-7)
The Quran indicates that mountains have deep roots by using the word stakes to describe them. In fact mountains do have deep roots, and the word stakes is an accurate description for them. A book titled 'Earth' by Geophysicist Frank Press explains that mountains are like stakes, and are buried deep under the surface of the earth. Mount Everest (pictured below), the height of which is approximately 9 km above ground, has a root deeper than 125 km.
The fact that mountains have deep 'stake' like roots was not known, until after the development of the theory of plate tectonics in the beginning of the 20th century.[6]
 
5. Expansion of the Universe
 
At a time when the science of Astronomy was still primitive, the expansion of the universe was described in Quran:
"And it is We who have built the Universe with [Our creative] power and keep expanding it." (Quran 51:47)
The fact that the universe is expanding was discovered in the last century. The physicist Stephen Hawking in his book 'A Brief History of Time' writes, "The discovery that the universe is expanding was one of the great intellectual revolutions of the 20th century.".
The Quran mentioned the expansion of the universe even before the invention of the telescope!
 
6. Sun's Orbit
 
In 1512 the astronomer Nicholas Copernicus put forward his theory that the Sun is motionless at the centre of the solar system, and that the planets revolve around it. The belief that the Sun is stationary was widespread amongst astronomers until the 20th century. It is now a well-established scientific fact that the Sun is not stationary, but is moving in an orbit around the centre of our Milky Way galaxy[7].
The Quran mentions the orbit of the Sun:
"It is He who created night and day, the Sun and the Moon, each floating in its orbit." (Quran 21:33)
The Quran would have been wrong according to astronomers just a couple of decades ago. But we now know that the Quranic account of the Sun's motion is consistent with modern Astronomy.
 
7. The Ocean
 
The Quran uses imagery to covey its deep meanings, here it describes the state of the unbelievers as:
"Darkness out in a deep ocean which is covered by waves, above which are waves, above which are clouds, layers of darkness, one upon the other. When one puts out his hand [therein], he can hardly see it. Those God gives no light to, they have no light." (Quran 24:40)
It is commonly thought that waves only occur on the surface of the ocean. However oceanographers have discovered that there are internal waves that take place below the surface of the ocean. These waves are invisible to the human eye, and can only be detected by specialist equipment[8]. The Quran mentions darkness in a deep ocean above which are waves, above which are waves, then clouds above that. This description is not only remarkable because it describes the internal waves in the ocean, but also because it describes darkness deep in the ocean. A human being can dive no more than 70 metres without breathing equipment. Light is present at that depth, but if we go down 1000 metres it is completely dark[9]. 1400 years ago there were no submarines or specialist equipment to discover internal waves or the darkness deep inside the oceans.
 
8. Lying and Movement
 
There was a cruel oppressive tribal leader named Abu Jahl who lived during the time of Prophet Muhammad, may the mercy and blessings of God be upon him. God revealed a verse of the Quran to warn him:
"No Indeed! If he does not stop, We will seize him by the forehead, his lying, sinful forehead." (Quran 96:15-16)
God does not call this person a liar, but calls his forehead (the front part of the brain) 'lying' and 'sinful', and warns him to stop.
This verse is significant for two reasons. The first is that the front part of our brain is responsible for voluntary movement[10].This is known as the frontal lobe. A book titled 'Essentials of Anatomy and Physiology' which includes the results of research on the functions of this area states: The motivation and the foresight to plan and initiate movements occur in the anterior portion of the frontal lobes, the prefrontal area[11]. The part of the brain that is responsible for movement is said to be seized if the man does not stop.
Secondly, numerous studies have shown that this same region (frontal lobe) is responsible for the lying function of the brain[12]. One such study at the University of Pennsylvania in which volunteers were asked questions during a computerized interrogation, it was found that when the volunteers were lying there was significantly increased activity in the prefrontal and premotor cortices (frontal lobe region)[13].
The front part of the brain is responsible for movement and lying. The Quran links movement and lying to this area. These functions of the frontal lobe were discovered with medical imaging equipment which was developed in the 20th century.
 
9. Pain Receptors
 
For a long time it was thought that the sense of feeling and pain was dependent on the brain. However it has been discovered that there are pain receptors present in the skin[14]. Without these pain receptors, a person would not be able to feel pain.
Consider the following verse on pain:
"We shall send those who reject Our revelations to the (Hell) Fire. When their skins have been burned away, We shall replace them with new ones so that they may continue to feel the pain: God is Almighty, All-Wise." (Quran 4:56)
God tells the people who reject his message that when they are in Hell and their skins are burnt off (so they can't feel any pain), he will give them new skins so that they continue to feel the pain.
The Quran makes it clear that pain is dependent upon on the skin. The discovery of pain receptors in the skin is a fairly recent discovery for Biology.
 
Conclusion
 
These are just some of the many scientific facts found in the Quran. It is important to note that the Quran is not a book of science, but that it is consistent with science. To claim that scientific facts in the Quran are due to coincidence would be irrational. The best explanation is that God revealed this knowledge to the Prophet Muhammad.
Just like the Quran contains knowledge about the natural world, it also contains information about the inner dimensions of our souls. It relates to our feelings, wants and needs. The Quran informs us that we have a purpose in life, and that following God's guidance will lead us to inner peace in this life, and Paradise in the hereafter. And that rejection of his message will lead to depression in this life and Hellfire after death.
"We shall show them Our signs in the Universe and within themselves, until it becomes clear to them that this is the Truth. Is it not enough that your Lord is the witness of all things?" (Quran 41:53)
 
http://www.islamreligion.com/articles/5195/
 
Thank you
red floyd <no.spam@its.invalid>: May 05 11:51AM -0700

On 5/5/2015 8:24 AM, Stefan Ram wrote:
 
> void f( V * & q ){ ::std::cout << q->i << '\n'; }
 
> int main(){ V * p = nullptr; f( p ); }
 
> »q« is a reference, and it /is/ null!
 
Perhaps a better way of phrasing it is thus:
 
Reference: the referenced object always exists (modulo UB, of course)
Pointer: the object pointed to may or may not (nullptr) exist
(again, modulo UB)
Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid>: May 05 09:41PM +0200


> void f( V * & q ){ ::std::cout << ::std::boolalpha <<( q == 0 )<< '\n'; }
 
> int main(){ V * p = nullptr; f( p ); }
 
> Saying, »q is not null«, when in fact »q == 0« /is/ true,
 
The reference q is not null, i.e., it actually references a valid
object.
 
In "q == 0" you are not comparing the reference to 0, you are comparing
the referenced oject (a pointer) to 0.
 
(BTW: you should use nullptr instead of 0, were it only for
consistency.)
 
> is something that can be understood by all those who can guess what
> the intended meaning is, but might not be true by a strict reading
> of the wording.
 
I can't parse this.
 
-- Alain.
"Tobias Müller" <troplin@bluewin.ch>: May 05 07:57PM


> void f( V * & q ){ ::std::cout << q->i << '\n'; }
 
> int main(){ V * p = nullptr; f( p ); }
 
> »q« is a reference, and it /is/ null!
 
The statement that a reference can (or cannot) be null makes no sense to
begin with.
A reference is an abstract concept. It's not a variable and most important
it is/has no value. It refers _refers_ to a variable, which can have a
value, but not the reference by itself.
 
Tobi
Victor Bazarov <v.bazarov@comcast.invalid>: May 05 01:11PM -0400

On 5/5/2015 12:51 PM, Doug Mika wrote:
> Yes that worked nicely, and I'll admit, I haven't yet read about the
std::function template but I hope someone could quickly explain the
following line:
> mapIntToString1(ReverseSort<int>);
 
> function<bool(const int&, const int&)> - defines type as function
> that
takes two int's and returns a bool. Check
 
> mapIntToString1(ReverseSort<int>) - calls the constructor of map
> that
takes key_compare as argument, in this case a function pointer. Is this
correct?
 
'function< blah >' is a class (type), first of all. It can be used to
create an object, and that's the most important thing as far as map and
other containers where a comparator is needed, are concerned. In place
of 'blah' you write the type of the function. Basically, it's the
sequence of tokens as if you declare a function but omit the name, and
the names of the argument.
 
mapI2S(ReverseSort<int>) declares, defines, and initializes the object
of the type map<int,...>. As the process of the initialization, the
constructor is called and 'ReverseSort<int>' (the argument to the c-tor)
is converted to the 'function<bool...>' object.
 
V
--
I do not respond to top-posted replies, please don't ask
Paavo Helde <myfirstname@osa.pri.ee>: May 05 01:29PM -0500

Doug Mika <dougmmika@gmail.com> wrote in
> bool ReverseSort(const KeyType& key1, const KeyType& key2){
> return (key1 > key2);
> }
 
You are confusing two templates - your function template ReverseSort and
the class template std::map. You need to instantiate both. ReverseSort is
easy, it is instantiated with type int. Std::map needs to be also
instantiated with a type. However, ReverseSort is a template, not a
function, so it is not a type and does not have a type. When
instantiated, it may generate functions of potentially infinite number of
types.
 
The function type involves its parameter and return types. As I mentioned
before, it is easiest to work with function pointers. A suitable type is
a pointer type, namely a pointer which points to functions taking two
ints and returns bool:
 
typedef bool (*MyFuncType)(const int&, const int&);
 
This is the type which you can use for instantiating std::map. Note that
this is not a template (because templates are not types, they just can
generate types; you could use your template to define all kind of types,
but this requires struct or class templates).
 
This function type is quite generic. How does it know it has to use your
ReverseSort? Well, you have to tell it, by passing the value of the above
type to the std::map constructor. This value is of course just a pointer
to a suitable function, namely to the correct instantiation of your
function template.
 
The whole program looks like this:
 
#include <map>
#include <string>
 
template<typename KeyType>
bool ReverseSort(const KeyType& key1, const KeyType& key2){
return (key1 > key2);
}
 
typedef bool (*MyFuncType)(const int&, const int&);
 
int main() {
std::map<int, std::string> someOtherMap;

std::map<int, std::string, MyFuncType>
mapIntToString(
someOtherMap.cbegin(),
someOtherMap.cend(),
&ReverseSort<int>);
}
 
Here, &ReverseSort<int> gives you a function pointer. A function pointer
is an object and can be passed here easily. Note that this is
conceptually passed at run-time, so the compiler will have much more
trouble optimizing the code and inlining your function (as opposed to the
functor variant).
 
 
> None of the ones below work? Why?
> map<int, string, ReverseSort> mapIntToString (someOtherMap.cbegin(),
> someOtherMap.cend());
 
ReverseSort is not a type.
 
 
> map<int, string> mapIntToString3 (mapIntToString1.cbegin(),
> mapIntToString1.cend(),ReverseSort<int>);
 
The default comparator type does not match ReverseSort<int>.

> map<int, string> mapIntToString3 (mapIntToString1.cbegin(),
> mapIntToString1.cend(),ReverseSort);
 
ReverseSort is not an object.
Doug Mika <dougmmika@gmail.com>: May 05 11:35AM -0700

One of the constructors of map is defined as follows:
 
explicit map (const key_compare& comp = key_compare(),
const allocator_type& alloc = allocator_type());
 
given this, why wouldn't the following map decleration work?
 
map<int, string> mapIntToString2 (mapIntToString1.cbegin(), mapIntToString1.cend(), ReverseSort<int>);
Paavo Helde <myfirstname@osa.pri.ee>: May 05 01:49PM -0500

Doug Mika <dougmmika@gmail.com> wrote in
 
> given this, why wouldn't the following map decleration work?
 
> map<int, string> mapIntToString2 (mapIntToString1.cbegin(),
> mapIntToString1.cend(), ReverseSort<int>);
 
I answered this in another reply just few minutes ago. Here, template
argument for comparator is the default (std::less<int>), but your passed
value is of a different type (a function (reference)). std::less is a
class, not a function type. You need to specify the correct type as the
template argument.
 
hth
Paavo
Bo Persson <bop@gmb.dk>: May 05 07:52PM +0200

On 2015-05-05 17:17, Stefan Ram wrote:
> happen? Is there a name for this "optimization" (akin to "RVO")?
 
> So, if it is guaranteed that it will happen for
 
> f( ::std::string const s )
 
std::string has a move constructor, so yes the temporary could be moved
into s. Or maybe RVO from operator+ would make the move unnecessary?
 
 
 
> , then one does not need to write
 
> f( ::std::string && s )
 
> . Then, what are the use-cases for »f( ::std::string && s )«?
 
If f might want to pass the reference on to some other function, perhaps
 
g(std::forward<std::string>(s));
 
 
 
Bo Persson
Bo Persson <bop@gmb.dk>: May 05 07:43PM +0200

On 2015-05-05 17:05, Stefan Ram wrote:
 
> l.cbegin()
> ::std::cbegin( l )
 
> , and why is there no
 
Part of this is likely just an historical accident. In C++98 none of the
containers had cbegin or cend. When they were added by one C++11
proposal, std::initializer_list was in another proposal, and apparently
nobody thought about cross checking that.
 
The free functions, added even later, should work in all cases.
 
 
Bo Persson
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: