comp.lang.c++
http://groups.google.com/group/comp.lang.c++?hl=en
comp.lang.c++@googlegroups.com
Today's topics:
* Practice of basic concepts - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/44be24048e34514b?hl=en
* Behavior of the local class - 4 messages, 4 authors
http://groups.google.com/group/comp.lang.c++/t/485b73a7b838fdff?hl=en
* Happy New Year! - 4 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/ba5c770fb7bf9d5f?hl=en
* Announcing new C/C++ performance profiler: aprof - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/d13ff88370c0f505?hl=en
* Is It Possible...? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/28857fba3308f564?hl=en
* The Economic System of Islam - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/929b5d1439dc45a3?hl=en
* Why does this template code compile? - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/5932edb3c0ed2de6?hl=en
* C++/QT/ARM Processors Cross-compiling/Programming Problem - 2 messages, 2
authors
http://groups.google.com/group/comp.lang.c++/t/32d49ff56804bf40?hl=en
* Friendly GUI for windows building? - 7 messages, 6 authors
http://groups.google.com/group/comp.lang.c++/t/c865fa27ccf9e327?hl=en
==============================================================================
TOPIC: Practice of basic concepts
http://groups.google.com/group/comp.lang.c++/t/44be24048e34514b?hl=en
==============================================================================
== 1 of 3 ==
Date: Wed, Jan 1 2014 2:00 pm
From: Melzzzzz
On Wed, 1 Jan 2014 13:43:55 -0600
"osmium" <r124c4u102@comcast.net> wrote:
> "Ernest G. Dakota" wrote:
>
> > --
> > Deut. 23:1 No man whose testicles have been crushed or whose organ
> > has been cut off may become a member of the Assembly of God.
>
> Is that a reward or a punishment?
>
>
I think that's quote from Bible.
--
Have a place for everything and keep the thing somewhere else; this is
not advice, it is merely custom.
-- Mark Twain
== 2 of 3 ==
Date: Wed, Jan 1 2014 10:38 pm
From: David Brown
On 01/01/14 22:55, Ernest G. Dakota wrote:
> Jorgen Grahn wrote:
>
>> On Wed, 2014-01-01, Ernest G. Dakota wrote:
>>> TwistedRoar wrote:
>>>
>>>> I had already heard a lot about that book, I'm going after it right
>>>> now.
>>>> Thank you!
>>>
>>> Waste of time. Never fall for this shit.
>>> Focus on what you want to do, then do exactly that.
>>
>> Unless you follow that up with a proper explanation, I count that as
>> trying to mislead a newbie coming here for advice. A rotten thing to
>> do.
>
> No, you are simply a lying imbecile. Trying to sell products? What a lame
> thing to do on usenet. Shame
>
You do realise that Jorgen is not selling anything here? He is pointing
to some useful exercises available freely online, along with a book by
the guy that made the C++ language. (That does not necessarily imply
that Stroustrup writes the best C++ books - though it turns out that he
/does/ write good books.)
Focusing on a particular aspect of C++ could be a good idea - if the OP
wants to write games, then a book on "C++ for games development" might
be a good choice. But at the moment he is looking for general C++ help
and pointers, and that is what he has been getting here.
== 3 of 3 ==
Date: Thurs, Jan 2 2014 5:52 am
From: Victor Bazarov
On 1/1/2014 3:02 PM, Stefan Ram wrote:
>[..]
> ::std::cout << /* not tested */
> " | 0 1 2 3 4 5 6 7 8 9\n"
> "--|----------------------------------------\n"
^^^^^
I'd use a plus instead of the vertical line here.
> " 0| 0 0 0 0 0 0 0 0 0 0\n"
> " 1| 0 1 2 3 4 5 6 7 8 9\n"
> " 2| 0 2 4 6 8 10 12 14 16 18\n"
> " 3| 0 3 6 9 12 15 18 21 24 27\n"
> " 4| 0 4 8 12 16 20 24 28 32 36\n"
> " 5| 0 5 10 15 20 25 30 35 40 45\n"
> " 6| 0 6 12 18 24 30 36 42 48 54\n"
> " 7| 0 7 14 21 28 35 42 49 56 63\n"
> " 8| 0 8 16 24 32 40 48 56 64 72\n"
> " 9| 0 9 18 27 36 45 54 63 72 81\n";
>
V
--
I do not respond to top-posted replies, please don't ask
==============================================================================
TOPIC: Behavior of the local class
http://groups.google.com/group/comp.lang.c++/t/485b73a7b838fdff?hl=en
==============================================================================
== 1 of 4 ==
Date: Thurs, Jan 2 2014 1:22 am
From: somenath
I am not able to understand why the following program does not compile.
#include<iostream>
using namespace std;
template <class T >
void Fun(T t)
{
static int i = t;
class Test {
public:
Test( int t1) {
cout<<"Value = "<<i<<endl;
}
};
Test tt(t);
}
int main(void)
{
Fun<int >(5);
return 0;
}
Whenever I try to compile the program I get the following error
g++ LocalClass.cpp
/tmp/ccfEKvyT.o:LocalClass.cpp:(.text+0x2b): undefined reference to `i'
collect2: ld returned 1 exit status
But I am aware that local class can access the static local variable of enclosing function. The following program proves that as well.
#include<iostream>
using namespace std;
void Fun(int t)
{
static int i=t;
class Test {
public:
Test( int t1) {
cout<<"Value = "<<i<<endl;
}
};
Test tt(t);
}
int main(void)
{
Fun(5);
return 0;
}
This code compile fine. Then what is going wrong with template version of the program?
== 2 of 4 ==
Date: Thurs, Jan 2 2014 5:48 am
From: Victor Bazarov
On 1/2/2014 4:22 AM, somenath wrote:
> I am not able to understand why the following program does not compile.
> #include<iostream>
> using namespace std;
>
> template <class T >
> void Fun(T t)
> {
> static int i = t;
>
> class Test {
> public:
> Test( int t1) {
> cout<<"Value = "<<i<<endl;
> }
> };
> Test tt(t);
>
> }
>
>
> int main(void)
> {
> Fun<int >(5);
> return 0;
>
> }
> Whenever I try to compile the program I get the following error
> g++ LocalClass.cpp
> /tmp/ccfEKvyT.o:LocalClass.cpp:(.text+0x2b): undefined reference to `i'
> collect2: ld returned 1 exit status
You must be using a buggy version of the compiler/linker. It compiles
and links (and runs) just fine with VC++ 2012.
> [..]
V
--
I do not respond to top-posted replies, please don't ask
== 3 of 4 ==
Date: Thurs, Jan 2 2014 7:15 am
From: "Alf P. Steinbach"
On 02.01.2014 10:22, somenath wrote:
> I am not able to understand why the following program does not compile.
> #include<iostream>
> using namespace std;
>
> template <class T >
> void Fun(T t)
> {
> static int i = t;
>
> class Test {
> public:
> Test( int t1) {
> cout<<"Value = "<<i<<endl;
> }
> };
> Test tt(t);
>
> }
>
>
> int main(void)
> {
> Fun<int >(5);
> return 0;
>
> }
> Whenever I try to compile the program I get the following error
> g++ LocalClass.cpp
> /tmp/ccfEKvyT.o:LocalClass.cpp:(.text+0x2b): undefined reference to `i'
> collect2: ld returned 1 exit status
This is known g++ bug, already reported at
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52688
As a workaround you can pass the referenced static variable as an
argument, or maybe move it inside the class, or ...
Cheers & hth.,
- Alf
== 4 of 4 ==
Date: Sat, Jan 4 2014 11:18 am
From: "K. Frank"
Hi somenath (and Alf and Victor)!
On Thursday, January 2, 2014 10:15:57 AM UTC-5, Alf P. Steinbach wrote:
> On 02.01.2014 10:22, somenath wrote:
> > I am not able to understand why the following program does not compile.
> > ...
> > Whenever I try to compile the program I get the following error
> > g++ LocalClass.cpp
> > /tmp/ccfEKvyT.o:LocalClass.cpp:(.text+0x2b): undefined reference to `i'
> > collect2: ld returned 1 exit status
>
> This is known g++ bug, already reported at
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52688
> As a workaround you can pass the referenced static variable as an
> argument, or maybe move it inside the class, or ...
>
> Cheers & hth.,
> - Alf
I tried this with my copy of g++.
For what it's worth, your code compiles and runs fine
when I compile it with a mingw-w64 version of g++:
C:\>g++ --version
g++ (rubenvb-4.8-stdthread) 4.8.1 20130324 (prerelease)
Happy New Year Hacking!
K. Frank
==============================================================================
TOPIC: Happy New Year!
http://groups.google.com/group/comp.lang.c++/t/ba5c770fb7bf9d5f?hl=en
==============================================================================
== 1 of 4 ==
Date: Wed, Jan 1 2014 6:01 pm
From: woodbrian77@gmail.com
On Wednesday, January 1, 2014 2:27:15 PM UTC-6, Ernest G. Dakota wrote:
>
> What's so happy at that?
>
>
> Ezekiel 4:12 Eat the bread as you would eat barley loaves. Bake the bread
> in front of people, using human excrement for fuel."
>
Sorry if you are facing hard times. I have an offer
that may be of interest to you.
http;//webEbenezer.net/TorahConnections.html
Brian
Ebenezer Enterprises - In G-d we trust.
http://webEbenezer.net
== 2 of 4 ==
Date: Thurs, Jan 2 2014 9:25 am
From: Mr Flibble
On 02/01/2014 02:01, woodbrian77@gmail.com wrote:
> On Wednesday, January 1, 2014 2:27:15 PM UTC-6, Ernest G. Dakota wrote:
>>
>> What's so happy at that?
>>
>>
>> Ezekiel 4:12 Eat the bread as you would eat barley loaves. Bake the bread
>> in front of people, using human excrement for fuel."
>>
>
> Sorry if you are facing hard times. I have an offer
> that may be of interest to you.
>
> http;//webEbenezer.net/TorahConnections.html
But only if you are not gay.
Again: the Torah is a book of fiction, your religion is a lie and your
god does not exist.
/Flibble
== 3 of 4 ==
Date: Thurs, Jan 2 2014 12:05 pm
From: woodbrian77@gmail.com
On Thursday, January 2, 2014 11:25:05 AM UTC-6, Mr Flibble wrote:
> On 02/01/2014 02:01, woodbrian77@gmail.com wrote:
>
> >
>
> > Sorry if you are facing hard times. I have an offer
>
> > that may be of interest to you.
>
> >
>
> > http;//webEbenezer.net/TorahConnections.html
>
> But only if you are not gay.
>
I'm willing to consider any project and am
willing to pay the referral money to anyone.
If the project were related to something I
disagree with though, I wouldn't work on it.
Like Gabriel Weinberg, I wouldn't invest in
a company that wants to make money on porn.
http://about.gabrielweinberg.com/
Brian
Ebenezer Enterprises - Trust in the L-rd
and lean not on your own understanding.
http://webEbenezer.net
== 4 of 4 ==
Date: Sat, Jan 4 2014 1:47 am
From: Saeed Amrollahi
On Wednesday, January 1, 2014 2:57:42 AM UTC+3:30, Alf P. Steinbach wrote:
> Yay! Another year!
>
>
>
> Cheers!
>
>
>
> - Alf (new year mode)
Happy new year Alf!
==============================================================================
TOPIC: Announcing new C/C++ performance profiler: aprof
http://groups.google.com/group/comp.lang.c++/t/d13ff88370c0f505?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Jan 2 2014 6:11 am
From: Emilio Coppa
Hi everyone,
We are developing a new Valgrind tool called aprof, a performance profiler for C/C++ designed to help developers understand how an application's performance scales as a function of its input data. The tool automatically generates, for each executed function, a 2D chart that relates performance to input size, yielding clues to the "big Oh" of the underlying algorithm and exposing possible asymptotic inefficiencies. Charts that analyze the input workloads are also generated, among many others.
The tool and a profile visualizer have been brewing for some time and we think they are mature enough to be released. For the time being, we're keeping them at:
https://code.google.com/p/aprof
Please check the wiki for a manual and a brief tutorial explaining the main goals of our profiler and how to use it. For an example of the kind of info one can get from aprof see, e.g., Frank Reininghaus' blog http://tinyurl.com/oyuud99.
We would be happy to hear about any experience, difficulties, questions, or suggestions about aprof.
Cheers,
Emilio Coppa
==============================================================================
TOPIC: Is It Possible...?
http://groups.google.com/group/comp.lang.c++/t/28857fba3308f564?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Jan 2 2014 6:55 pm
From: Luca Risolia
Thomas Flynn wrote:
> template<typename T, T RelayTeamType::*memb>
> bool cmp(const RelayTeamType & lhs,
> const RelayTeamType & rhs){
> return (lhs).*(memb) < (rhs).*(memb);
> }
>
>
> Here the cmp function is templatized on the member variable you want to
> sort by.
>
> You can compare two elements q u like
>
> cmp<time_t,&RelayTeamType::totalTime>(q,u);
> cmp<string,&RelayTeamType::rtTeamName>(q,u);
>
> and sort the vector like
>
> std::sort(rtVect.begin(),rtVect.end(),
> cmp<string, &RelayTeamType::rtTeamName>);
This is easier to use, as you don't need to specify any template arguments for
the comparator:
template<class C, class T>
struct cmp_ {
T C::*m;
constexpr cmp_(T C::*m) noexcept : m{m} { }
bool operator()(RelayTeamType const& a, RelayTeamType const& b) const
noexcept {
return (a.*m) < (b.*m);
}
};
template <class C, class T>
auto cmp(T C::*m) noexcept -> cmp_<C, T> {
return m;
}
std::sort(std::begin(rtVect), std::end(rtVect),
cmp(&RelayTeamType::rtTeamName));
==============================================================================
TOPIC: The Economic System of Islam
http://groups.google.com/group/comp.lang.c++/t/929b5d1439dc45a3?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Jan 3 2014 3:44 am
From: bv4bv4bv4@gmail.com
The Economic System of Islam
1-An introduction to the principles Islam has legislated to guide the economic system of society. Part 1: The sources from which the laws that guide economical activity are derived.
2-The Ideological Basis of Economic Activity and the general principles by which they are guided
Introduction
As a complete way of life, Islam has provided guidelines and rules for every sphere of life and society. Naturally, a functioning economic system is vital for a healthy society, as the consumption of goods and services, and the facilitation of this by a common medium of exchange, play a major role in allowing people to realize their material and other goals in life.
Islam has set some standards, based on justice and practicality, for such economic systems to be established. These standards aim to prevent the enmity that often occurs between different socioeconomic sections. Of course, it is true that the gathering of money concerns almost every human being who participates in transactions with others. Yet, while these standards recognize money as being among the most important elements in society, they do not lose sight of the fact that its position is secondary to the real purpose of human existence, which is the worship of God.
An Islamic economic system is not necessarily concerned with the precise amount of financial income and expenditure, imports and exports, and other economic statistics. While such matters are no doubt important, Islam is more concerned with the spirit of the economic system.
A society that implements Islamic laws and promotes Islamic manners will find that it bring together all the systems – social, economic, and so forth – that it deals with. Islam teaches that God has created provision for every person who He has brought to life. Therefore, the competition for natural resources that is presumed to exist among the nations of the world is an illusion. While the earth has sufficient bounty to satisfy the needs of mankind, the challenge for humans lies in discovering, extracting, processing, and distributing these resources to those who need them.
Islam consists of a set of beliefs which organizes the relationship between the individual and his Creator; between the person and other human beings; between the person and universe; and even the relationship of the person to himself. In that sense, Islam regulates human behavior, and one type of human behavior is economic behavior. Economic behavior is dealt by Muslims as a means of production, distribution, and consumption of goods and services. In Islam, human behavior -whether in the economic area or others - is not value free; nor is it value neutral. It is connected with the ideological foundation of the faith.
The Sources of Islamic Economics
The fundamental sources of Islam - the Quran and the Sunnah of the Prophet[1] - provide guidelines for economic behavior and a blueprint of how the economic system of a society should be organized. Therefore, the values and objectives of all "Islamic" economic systems must necessarily conform to, and comply with, the principles derived from these fundamental sources. The purpose of these articles is to outline the most salient characteristics of an economic system based on the fundamental sources of Islam. The focus here is on the principal features of the Islamic system.
The Islamic economic system is defined by a network of rules called the Shariah. The rules which are contained in the Shariah are both constitutive and regulative, meaning that they either lay the rules for the creation of economic entities and systems, as well the rules which regulate existing one. As an integral part of the revelation, the Shariah is the guide for human action which encompasses every aspect of life – spiritual, individual, social, political, cultural, and economic. It provides a scale by which all actions, whether on the part of the individual agents, society, and the state, are classified in regards to their legality. Thus there are five types of actions recognized, namely: obligatory; recommended; permissible; discouraged; and forbidden. This classification is also inclusive of economic behavior.
The basic source of the Shariah in Islam is the Quran and the Sunnah, which include all the necessary rules of the Shariah as guidance for mankind. The Sunnah further explains these rules by the practical application of Prophet Muhammad, may the mercy and blessings of God be upon him. The expansion of the regulative rules of the Shariah and their extensions to new situations in later times was accomplished with the aid of consensus of the scholars, analogical reasoning - which derived rules by discerning an analogy between new problems and those existing in the primary sources - and finally, through textual reasoning of scholars specialized in the Shariah. These five sources - the Quran, the Sunnah, consensus of the scholars, analogical reasoning, and textual reasoning - constitute the components of the Shariah, and these components are also used as a basis for governing economic affairs.
Justice
In summary, we can say that the Islamic Economic system is based upon the notion of justice It is through justice that the existence of the rules governing the economic behavior of the individual and economic institutions in Islam can be understood. Justice in Islam is a multifaceted concept, and there several words exist to define it. The most common word in usage which refers to the overall concept of justice is the Arabic word "adl". This word and its many synonyms imply the concepts of "right", as equivalent to fairness, "putting things in their proper place", "equality", "equalizing", "balance", "temperance" and "moderation." In practice, justice is defined as acting in accordance with the Shariah, which, in turn, contains both substantive and procedural justice[2] covering economic issues. Substantive justice consists of those elements of justice contained in the substance of the Shariah, while procedural justice consists of rules of procedure assuring the attainment of justice contained in the substance of the Law. The notion of economic justice, and its attendant concept of distributive justice, [3] is particularly important as an identifying characteristic of the Islamic economic system. The rules governing permissible and forbidden economic behavior on the part of consumers, producers and government, as well as questions of property rights, and of the production and distribution of wealth, are all based on the Islamic view of justice.
The following topics will be discussed in the following articles:
(a) individual obligations, rights, and self-interest;
(b) property rights;
(c) importance of contracts;
(d) work and wealth;
(e) the concept of barakah;
(f) economic justice;
(g) prohibition of interest (riba);
(h) competition and cooperation; and
(i) the role of the state.
The Ideological Basis of Economic Activity
The ideological basis in Islam may be summarized into six basic principles:
The cornerstone is that everything has to start from the belief in God as the Creator, Lord, and Sovereign of the universe. This implies willingness to submit to God's will, to accept His guidance, and to have complete and unqualified servitude to Him. This means that Muslims - individually and collectively - should not imitate or emulate any other system if it differs from their particular principles, for example, the system of usury or interest.
The second basic principle is that Islam, as a religion, is a complete way of life; something that guides a person's life in all its aspects: the moral, social, ethical, economic, political, etc. All of these aspects are based on the guidance of God. Therefore, it is not a question of the person's acceptance of God's teaching in one matter and the refusal of acceptance in another. Everything has to be within that basic guidance.
"…And we have revealed to you in stages this book, a clarification of all things, a guidance, a mercy, and glad tidings…" (Quran 16:89)
A third principle is that God created human beings on earth as His trustees, which means that everyone is created to fulfill a certain responsibility on this earth. God has entrusted human beings with free will in order that they live their lives according to the moral and ethical values that He Himself provided. In addition, Islam provides an opportunity in material progress, thereby combining moral, social, and material progress, all interlinked in harmony.
The fourth principle is that God, in order to help humankind to fulfill the responsibility of trusteeship, has made everything in this universe subservient to them. There are many verses in the Quran that suggest this meaning, such as:
"God is He Who made subservient to you the sea that the ships may run therein by His command, and that you may seek of His grace, and that you may give thanks." (Quran 45:12)
This does not mean, however, that humans are given free reign to use and abuse the resources God has provided us however we choose. Rather, there are many verses that urge humankind to harness the various resources that God has made available to them on this earth responsibly. Humans are encouraged to enjoy of the good things that God has created, but they are to do so within the boundaries that He has given. Doing so is not regarded as sinful as long as it follows His path and does not transgress His limits. God says:
"It is He Who produces gardens, with trellises and without, and dates, and tilth with produce of all kinds, and olives and pomegranates, similar (in kind) and different (in variety): eat of their fruit in their season, but render the dues that are proper on the day that the harvest is gathered. But waste not by excess: for God loves not those who waste." (Quran 6:141)
The fifth principle is the principle of accountability in the Hereafter. God has given human beings trusteeship and resources. This means that every single person will be questioned on the Day of Judgment as to how he or she behaved whilst enjoying his or her earthly life. This, of course, includes our economic behavior. God says:
"And then on that Day (the Day of Resurrection) you will be called to account for every comfort and delight [we bestowed upon you]." (Quran 102:8)
The sixth principle is that the variation in wealth among people in itself does not give a person either inferiority or superiority. Rather, poverty and affluence are in the total control of God Who, out of His Infinite Justice and Wisdom, has specified these things for whom he chooses.
"Indeed God increases provision to whom He pleases and straitens it [in regards to others]…" (Quran 13:26)
Affluence, like poverty, is also seen as a trial from God, one through which it is seen what one will do with their wealth – indulge oneself or use constructively in ways legislated in the religion, God says:
"Your wealth and your children are only a trial, whereas God! With Him is a great reward (Paradise)."(Quran 64:15)
After being bestowed with numerous gifts and bounties and a kingdom incomparable to any other on the earth, God in the Quran narrates that Solomon said:
"…This is from the bounties of my Lord, to test me whether I will be thankful or ungrateful…" (Quran 27:40)
God is not concerned with the amount of wealth a person may have amassed, their beauty or color, but rather, His measure of honor is the piety of the hearts. God says:
"On humankind! Indeed We created you from a male and female, and we made you different nations and tribes, that you may come to know one other. Indeed the most honored amongst you are the most God-conscious." (Quran 49:13)
The Prophet also said:
"Indeed God is not concerned with your appearances nor your wealth, but rather your hearts and deeds." (Saheeh Muslim)
As one can immediately surmise from these principles that the Islamic economic system is radically different from others, due to the difference of the values upon which it is based. In a capitalist society, one may see certain rules of economics which take precedence over moral and ethical values due to the intrinsic nature and values of that system. The same may be seen in communist, socialist and other societies as well. From the principles mentioned in these articles does the Islamic system of economics spring, striking balance between personal benefit and the benefit of society as a whole, as well as mundane profits and spiritual gains, all which ensure that one gain the Pleasure of the Lord of the Worlds.
[1] The Sunnah is general body of narrations of the speech, deeds, and tacit approvals of the Prophet.
[2] "Substantive justice means reaching the 'right' result. Procedural justice means getting the result in the 'right' way." (A speech entitled "Effective Arbitration Techniques in a Global Context" delivered by the Secretary for Justice of Hong Kong ,Ms Elsie Leung)
[3] "Normative principles designed to allocate goods in limited supply relative to demand." Stanford Encyclopedia of Philosophy:
(http://plato.stanford.edu/entries/justice-distributive/)
http://www.islamhouse.com/429666/en/en/articles/The_Economic_System_of_Islam
Thank you
==============================================================================
TOPIC: Why does this template code compile?
http://groups.google.com/group/comp.lang.c++/t/5932edb3c0ed2de6?hl=en
==============================================================================
== 1 of 3 ==
Date: Fri, Jan 3 2014 4:25 pm
From: Peter
In "C++ Templates The Complete Guide" book by Vandevoorde
and Josuttis I found the following template definition
near the end of chapter 8.2 ("Template Arguments"):
template<template<typename T, T*> class Buf>
class Lexer
{
static char storage[5];
Buf<char, &Lexer<Buf>::storage> buf;
};
Buf is a template template argument whose template
arguments are: type parameter T and unnamed non-type
parameter - a pointer to T. In the definition of Lexer,
Buf is instantiated so that T = char and second argument
(of type T*) is &Lexer<Buf>::storage, but why is this
second substitution correct?
How does &Lexer<Buf>::storage resolve to char*?
Here's my reasoning.
Lex<Buf>::storage is of type char[5],
&Lex<Buf>::storage is of type char(*)[5].
If we had:
Buf<char, Lexer<Buf>::storage> buf;
instead of:
Buf<char, &Lexer<Buf>::storage> buf;
in the definition of Lexer template then
Lexer<Buf>::storage would decay to char*, but why
can the template be instantiated with
&Lexer<Buf>::storage as well? I tested both definitions
here:
http://www.compileonline.com/compile_cpp11_online.php
and they both compile.
However, if I try to instantiate Lexer with
&Lexer<Buf>::storage as second argument to Buf, I get
a compilation error as expected. Here's a complete example:
template<template<typename T, T*> class Buf>
class Lexer
{
static char storage[5];
Buf<char, &Lexer<Buf>::storage> buf;
};
template<typename T, T*>
class Foo
{
};
int main()
{
Lexer<Foo> lex;
return 0;
}
Now:
1) if I try to compile the above I get the following error:
main.cpp: In instantiation of 'class Lexer<Foo>':
main.cpp:15:15: required from here
main.cpp:5:37: error: could not convert template argument
'& Lexer<Foo>::storage' to 'char*'
2) if I change "&Lexer<Buf>::storage" to
"Lexer<Buf>::storage" the code compiles
3) if I comment out the instantiation of Lexer from main()
the code compiles with either &Lexer<Buf>::storage or
Lexer<Buf>::storage as second argument to Buf.
Can you explain what happens here and why Buf template can
be instantiated with either of the two arguments?
== 2 of 3 ==
Date: Fri, Jan 3 2014 4:55 pm
From: Victor Bazarov
On 1/3/2014 7:25 PM, Peter wrote:
> In "C++ Templates The Complete Guide" book by Vandevoorde
> and Josuttis I found the following template definition
> near the end of chapter 8.2 ("Template Arguments"):
>
> template<template<typename T, T*> class Buf>
> class Lexer
> {
> static char storage[5];
> Buf<char, &Lexer<Buf>::storage> buf;
> };
>
> Buf is a template template argument whose template
> arguments are: type parameter T and unnamed non-type
> parameter - a pointer to T. In the definition of Lexer,
> Buf is instantiated so that T = char and second argument
> (of type T*) is &Lexer<Buf>::storage, but why is this
> second substitution correct?
> How does &Lexer<Buf>::storage resolve to char*?
I think it doesn't "resolve". Not until you actually instantiate the
template.
> Here's my reasoning.
>
> Lex<Buf>::storage is of type char[5],
> &Lex<Buf>::storage is of type char(*)[5].
No. It's not. &(Lex<Buf>::storage) would be a pointer to an array.
But since the parentheses are missing (see 5.3.1), the expression is a
pointer-to-member.
> If we had:
>
> Buf<char, Lexer<Buf>::storage> buf;
>
> instead of:
>
> Buf<char, &Lexer<Buf>::storage> buf;
>
> in the definition of Lexer template then
> Lexer<Buf>::storage would decay to char*, but why
> can the template be instantiated with
> &Lexer<Buf>::storage as well? I tested both definitions
> here:
>
> http://www.compileonline.com/compile_cpp11_online.php
>
> and they both compile.
Unless you try to instantiate the 'Lexer' template, the code only
undergoes syntax check and not the actual compilation (no conversions
are attempted).
> However, if I try to instantiate Lexer with
> &Lexer<Buf>::storage as second argument to Buf, I get
> a compilation error as expected. Here's a complete example:
>
>
> template<template<typename T, T*> class Buf>
> class Lexer
> {
> static char storage[5];
> Buf<char, &Lexer<Buf>::storage> buf;
> };
>
> template<typename T, T*>
> class Foo
> {
> };
>
> int main()
> {
> Lexer<Foo> lex;
> return 0;
> }
>
> Now:
>
> 1) if I try to compile the above I get the following error:
>
> main.cpp: In instantiation of 'class Lexer<Foo>':
> main.cpp:15:15: required from here
> main.cpp:5:37: error: could not convert template argument
> '& Lexer<Foo>::storage' to 'char*'
>
> 2) if I change "&Lexer<Buf>::storage" to
> "Lexer<Buf>::storage" the code compiles
>
> 3) if I comment out the instantiation of Lexer from main()
> the code compiles with either &Lexer<Buf>::storage or
> Lexer<Buf>::storage as second argument to Buf.
Which most likely means that the conversion is never attempted.
> Can you explain what happens here and why Buf template can
> be instantiated with either of the two arguments?
I can't explain how 'Buf' can be instantiated if it acutally can't be
instantiated (you get the error when you try to instantiate it).
V
--
I do not respond to top-posted replies, please don't ask
== 3 of 3 ==
Date: Fri, Jan 3 2014 8:36 pm
From: "Alf P. Steinbach"
On 04.01.2014 01:25, Peter wrote:
> In "C++ Templates The Complete Guide" book by Vandevoorde
> and Josuttis I found the following template definition
> near the end of chapter 8.2 ("Template Arguments"):
>
> template<template<typename T, T*> class Buf>
> class Lexer
> {
> static char storage[5];
> Buf<char, &Lexer<Buf>::storage> buf;
> };
>
> Buf is a template template argument whose template
> arguments are: type parameter T and unnamed non-type
> parameter - a pointer to T. In the definition of Lexer,
> Buf is instantiated so that T = char and second argument
> (of type T*) is &Lexer<Buf>::storage, but why is this
> second substitution correct?
It isn't.
> How does &Lexer<Buf>::storage resolve to char*?
It doesn't. The code is ungood.
> Here's my reasoning.
>
> Lex<Buf>::storage is of type char[5],
> &Lex<Buf>::storage is of type char(*)[5].
Yep.
> If we had:
>
> Buf<char, Lexer<Buf>::storage> buf;
>
> instead of:
>
> Buf<char, &Lexer<Buf>::storage> buf;
>
> in the definition of Lexer template then
> Lexer<Buf>::storage would decay to char*, but why
> can the template be instantiated with
> &Lexer<Buf>::storage as well?
It can't.
> I tested both definitions here:
>
> http://www.compileonline.com/compile_cpp11_online.php
>
> and they both compile.
Strange, it uses g++ 4.7.2 and that template definition (when
instantiated) does not compile with g++ 4.7.2 on my system.
Wait, lemme test that with the online compiler...
Nope, it failed:
[quote]
main.cpp: In instantiation of 'class Lexer<Foo>':
main.cpp:15:15: required from here
main.cpp:5:36: error: could not convert template argument '&
Lexer<Foo>::storage' to 'char*'
Buf<char, &Lexer<Buf>::storage> buf;
[/quote]
> However, if I try to instantiate Lexer with
> &Lexer<Buf>::storage as second argument to Buf, I get
> a compilation error as expected.
This doesn't make sense. It's the &Lexer<Buf>::storage that you claimed
(apparently incorrectly) compiled fine.
> Here's a complete example:
>
>
> template<template<typename T, T*> class Buf>
> class Lexer
> {
> static char storage[5];
> Buf<char, &Lexer<Buf>::storage> buf;
> };
>
> template<typename T, T*>
> class Foo
> {
> };
>
> int main()
> {
> Lexer<Foo> lex;
> return 0;
> }
>
> Now:
>
> 1) if I try to compile the above I get the following error:
>
> main.cpp: In instantiation of 'class Lexer<Foo>':
> main.cpp:15:15: required from here
> main.cpp:5:37: error: could not convert template argument
> '& Lexer<Foo>::storage' to 'char*'
>
> 2) if I change "&Lexer<Buf>::storage" to
> "Lexer<Buf>::storage" the code compiles
Yes, of course.
> 3) if I comment out the instantiation of Lexer from main()
> the code compiles with either &Lexer<Buf>::storage or
> Lexer<Buf>::storage as second argument to Buf.
Template definitions get only superficial analysis until they're
instantiated.
> Can you explain what happens here
Yes, the claim at the start, of the code compiling with the online
compiler, appears to be incorrect.
> and why Buf template can
> be instantiated with either of the two arguments?
It can't, it's a bug (of the typo kind) in the code.
I suggest reporting it to the book's errata list (check first if it's
there already):
http://www.josuttis.com/tmplbook/errata.html
Cheers & hth.,
- Alf
==============================================================================
TOPIC: C++/QT/ARM Processors Cross-compiling/Programming Problem
http://groups.google.com/group/comp.lang.c++/t/32d49ff56804bf40?hl=en
==============================================================================
== 1 of 2 ==
Date: Sat, Jan 4 2014 1:55 am
From: Saeed Amrollahi
dear all {C++|QT|Embedded Systems} developers
Hello
before anything, Happy new year.
In advance please accept my apologizes, if my question(s) are somehow off-topic.
If so, please give me some advice to choose appropriate discussion groups.
Recently, I'm involved in a QT/ARM Processor software development project.
The general components of the project is:
Processor: Mini440 FriendlyARM (400 MHz Samsung S3C2440 ARM926T),
www.friendlyarm.net
www.arm9.net
OS: Linux (Kernel version 2.6.32)
Programming Language: C++ (GCC/g++)
GUI Framework: QT
The main purpose of the project is to develop a GUI for the
embedded handheld device, using QT/Embedded Linux.
The output of command uname -a on host computer (development machine) is:
$ uname -a
Linux scorpion 3.5.0-39-generic #60~precise1-Ubuntu SMP Wed Aug 14 15:38:41 UTC 2013
x86_64 x86_64 x86_64 GNU/Linux
The output of command uname -a on embedded ARM-based device is:
Liunx FriendlyARM 2.6.32-FriendlyARM #5 Wed Jun 6 15:50:50
HKT 2012 armv4tl unknown.
My first question is:
Q. Is it important to host and target computers have the same architecture,
I mean both should be 32-bits (x86 or i586/i686) or both should be 64-bits (x86_64)?
I did the following steps:
1. I wrote a simple GUI using QT Creator (2.7.0) based on QT Designer (5.0.2)
on a desktop Linux machine (host computer)
2. Based on knowledge, I gained in last two months from books and Intenet about Cross-compiling,
and tool-chain and other many many related concepts, I found I have to install another
software from Trolltech called Qtopia, the Embedded version of QT. I tries
to install the latest version of Qtopia called qtopia-core-opensource-src-4.3.5
at this point I had a lot of problems at configuration, building and making the
software. One problem is g++ on host is 4.8.1 (very new), but the Qtopia
is for about 7 years ago. When I tries to build the Qtopia from source
the g++ compiler issues several C++ errors, for example:
error: 'ptrdiff_t' does not name a type
error: 'append' was not declared in this scope, and no declaration, where found
by argument-dependent lookup
Of course, I solved these problems, but it's obvious g++ issues these errors
because Qtopia was written using C++98, but g++ 4.8.1 is based on C++11
my questions are:
Q. Is it important to use which version of GCC with Qtopia?
another thing is which version of QT/Embedded should be used?
Q. Do I have to use the old versions of QT/Embedded like Qtopia or
I can use the newer versions like qt-everywhere-opensource-src-4.8.4?
another problem is about kernel version: is it important
Q. Is it important to host and target computers have the same kernel number (x.y.z)?
As you can see, I lost in details of cross-compiling and porting written software
from host to embedded device. I almost have no problem in using QT and writing C++ in desktop version.
At last, I appreciate you to give a your general but practical guideline/tips
to cross-compiling from x86 GCC to FreindlyARM platform.
Please shed some light.
TIA
-- Saeed Amrollahi Boyouki
== 2 of 2 ==
Date: Sat, Jan 4 2014 5:32 am
From: Christian Gollwitzer
Am 04.01.14 10:55, schrieb Saeed Amrollahi:
> dear all {C++|QT|Embedded Systems} developers
> Hello
> before anything, Happy new year.
> In advance please accept my apologizes, if my question(s) are somehow off-topic.
They are vastly off-topic. We din't discuss platform specific details
here, but only the C++ language itself (i.e. syntax of templates and
similar questions).
Try comp.arch.embedded
Christian
==============================================================================
TOPIC: Friendly GUI for windows building?
http://groups.google.com/group/comp.lang.c++/t/c865fa27ccf9e327?hl=en
==============================================================================
== 1 of 7 ==
Date: Sat, Jan 4 2014 2:51 am
From: Francois Guillet
Hi
Creating many windows and controls is very tedious when the parameters
of the CreateWindowEx function have to be set manually.
I'm looking for a tool able to build code automatically from drag and
drop of objects (buttons, check boxes, edit controls...) onto a first
empty window, and allowing repositionning, sizing, property settings...
This was provided in environments like C++ builder, but I'm searching
for a more light tool that would generate simple cpp and h files to
include in my project and that wouldn't need an obscure and heavy
library (I'm using codeblock/gcc/mingw).
Some advises?
Thanks
== 2 of 7 ==
Date: Sat, Jan 4 2014 9:22 am
From: ram@zedat.fu-berlin.de (Stefan Ram)
Francois Guillet <guillet.francois@wanadoo.fr> writes:
>Creating many windows and controls is very tedious when the parameters
>of the CreateWindowEx function have to be set manually.
>I'm looking for a tool able to build code automatically from drag and
>drop of objects (buttons, check boxes, edit controls...) onto a first
>empty window, and allowing repositionning, sizing, property settings...
This seems to reduce manual work by adding even more manual work.
What I do is to use the abstraction mechanisms of C++ to actually
reduce manual work. For example, I have written some helper functions
to build Windows dialogs, so that I now can write:
void appendDialogDescription( LPWORD lpw )
{ LPWORD const lpw0 = lpw; WORD n = 0; lpw = my_dialog( lpw, 0, 0 ); int y = 0;
lpw = my_label( lpw, ( y += 10 )+ 2, ID_TEXT_0, "&Hours" ); ++n;
lpw = my_edit( lpw, ( y += 0 )+ 0, ID_EDIT_0, "0" ); ++n;
lpw = my_label( lpw, ( y += 20 )+ 2, ID_TEXT_1, "&Minutes" ); ++n;
lpw = my_edit( lpw, ( y += 0 )+ 0, ID_EDIT_1, "0" ); ++n;
lpw = my_button( lpw, ( y += 20 )+ 0, ID_START, "&Start Shutdown" ); ++n;
lpw = my_button( lpw, ( y += 20 )+ 0, ID_EXIT, "&Exit" ); ++n;
my_dialog( lpw0, ( y += 20 )+ 0, n ); }
. The full code of the program can be found at
http://www.purl.org/stefan_ram/pub/c++-windows
. (Since it was written for tutorial purposes, it should not have gotten too
complicated, therefore I am still using fixed pixel dimensions, such as �10�
and �20�. In a real application these would be abstracted away too.)
Actually, these means of abstraction already are available in C, C++ is not
required.
The way of the programmer.
== 3 of 7 ==
Date: Sat, Jan 4 2014 9:36 am
From: "Alf P. Steinbach"
On 04.01.2014 11:51, Francois Guillet wrote:
>
> Creating many windows and controls is very tedious when the parameters
> of the CreateWindowEx function have to be set manually.
>
> I'm looking for a tool able to build code automatically from drag and
> drop of objects (buttons, check boxes, edit controls...) onto a first
> empty window, and allowing repositionning, sizing, property settings...
>
> This was provided in environments like C++ builder, but I'm searching
> for a more light tool that would generate simple cpp and h files to
> include in my project and that wouldn't need an obscure and heavy
> library (I'm using codeblock/gcc/mingw).
Look for "Resource Editors". These generate dialog resources and header
files. It's pretty old technology but sounds like what you're after.
A dialog can be main window.
You can create such a window from a dialog resource embedded in the
executable, by calling e.g. the DialogBox API function.
Cheers & hth.,
- Alf
== 4 of 7 ==
Date: Sat, Jan 4 2014 1:14 pm
From: David Brown
On 04/01/14 11:51, Francois Guillet wrote:
> Hi
>
> Creating many windows and controls is very tedious when the parameters
> of the CreateWindowEx function have to be set manually.
>
> I'm looking for a tool able to build code automatically from drag and
> drop of objects (buttons, check boxes, edit controls...) onto a first
> empty window, and allowing repositionning, sizing, property settings...
>
> This was provided in environments like C++ builder, but I'm searching
> for a more light tool that would generate simple cpp and h files to
> include in my project and that wouldn't need an obscure and heavy
> library (I'm using codeblock/gcc/mingw).
>
> Some advises?
>
> Thanks
What about using wxWidgets rather than raw Windows API? I don't know
where you draw lines for "heavy" and "light" libraries, but wxWidgets is
certainly not obscure - and there is very good support for it in
Code::Blocks.
== 5 of 7 ==
Date: Sat, Jan 4 2014 1:44 pm
From: Mr Flibble
On 04/01/2014 21:14, David Brown wrote:
> On 04/01/14 11:51, Francois Guillet wrote:
>> Hi
>>
>> Creating many windows and controls is very tedious when the parameters
>> of the CreateWindowEx function have to be set manually.
>>
>> I'm looking for a tool able to build code automatically from drag and
>> drop of objects (buttons, check boxes, edit controls...) onto a first
>> empty window, and allowing repositionning, sizing, property settings...
>>
>> This was provided in environments like C++ builder, but I'm searching
>> for a more light tool that would generate simple cpp and h files to
>> include in my project and that wouldn't need an obscure and heavy
>> library (I'm using codeblock/gcc/mingw).
>>
>> Some advises?
>>
>> Thanks
>
> What about using wxWidgets rather than raw Windows API? I don't know
> where you draw lines for "heavy" and "light" libraries, but wxWidgets is
> certainly not obscure - and there is very good support for it in
> Code::Blocks.
wxWidgets looks too much like MFC making it a bag of shite like MFC is a
bag of shite.
Try Qt; it is the least worst option.
/Flibble
== 6 of 7 ==
Date: Sat, Jan 4 2014 1:58 pm
From: Ike Shaffer
Mr Flibble wrote:
>> What about using wxWidgets rather than raw Windows API? I don't know
>> where you draw lines for "heavy" and "light" libraries, but wxWidgets
>> is certainly not obscure - and there is very good support for it in
>> Code::Blocks.
>
> wxWidgets looks too much like MFC making it a bag of shite like MFC is a
> bag of shite.
>
> Try Qt; it is the least worst option.
Yes, and pay for the shit as well. I guess he goes back to CreateWindowEx
== 7 of 7 ==
Date: Sat, Jan 4 2014 2:08 pm
From: Mr Flibble
On 04/01/2014 21:58, Ike Shaffer wrote:
> Mr Flibble wrote:
>
>>> What about using wxWidgets rather than raw Windows API? I don't know
>>> where you draw lines for "heavy" and "light" libraries, but wxWidgets
>>> is certainly not obscure - and there is very good support for it in
>>> Code::Blocks.
>>
>> wxWidgets looks too much like MFC making it a bag of shite like MFC is a
>> bag of shite.
>>
>> Try Qt; it is the least worst option.
>
> Yes, and pay for the shit as well. I guess he goes back to CreateWindowEx
You only pay for Qt if you want to link statically mate.
/Flibble
==============================================================================
You received this message because you are subscribed to the Google Groups "comp.lang.c++"
group.
To post to this group, visit http://groups.google.com/group/comp.lang.c++?hl=en
To unsubscribe from this group, send email to comp.lang.c+++unsubscribe@googlegroups.com
To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.c++/subscribe?hl=en
To report abuse, send email explaining the problem to abuse@googlegroups.com
==============================================================================
Google Groups: http://groups.google.com/?hl=en
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment