1

Topic: Compilation of templates

Experts With ++, again I address to you for the help. While only I start to get acquainted with templates so there was such question, I will be grateful, if who on fingers explains, how it works.
Here there is a template class vector, and there is at it a comparison operator <. We do, , so:

vector <int> iv1, iv2;
iv1.push_back (1);
iv2.push_back (2);
bool b = iv1> iv2;

And all works. And here if to try to compare vectors in which the objects lie, not defining comparison operator there will be a compilation error. And so I cannot understand, how it works. After all if to use a vector with incomparable elements, but not to cause comparing no errors arise. But after all the comparison operator there should be all the same certain, and the compiler should stumble about it. It turns out, vector all is compiled not completely at once, and in parts? That is, its operator <is not compiled, if is not caused anywhere and consequently in this case errors do not arise? Or it somehow on another is arranged? I, in view of poor knowledge With ++, cannot understand terrible source codes of standard library yet.

2

Re: Compilation of templates

the nail wrote:

Turns out, vector all is compiled not completely at once, and in parts?

Templates it only a variety of macroes. So yes, they are torn and
Are compiled only in a used part.

3

Re: Compilation of templates

Rusty nail;
The template is compiled only in that part which is used.
Namely - template functions which where are compiled only or caused and only template classes, which where or .
If function (template) is not caused, it is not compiled, but its syntactic analysis is thus produced, i.e. it should be syntactically correct (for example should not be passed ";", etc.).
It is called SFINAE.
Accordingly the operator "<" for a template vector will be compiled only if you compare a vector.

4

Re: Compilation of templates

The rusty nail, comparison operators for vectors are separate sample functions. It is natural, while they are not used, not .

5

Re: Compilation of templates

Anatoly Moskovsky wrote:

the Template is compiled only in that part which is used.
Namely - template functions which where are compiled only or caused and only template classes, which where or .
If function (template) is not caused, it is not compiled, but its syntactic analysis is thus produced, i.e. it should be syntactically correct (for example should not be passed ";", etc.).
It is called SFINAE.

SFINAE it is called not.

6

Re: Compilation of templates

a guest wrote:

the Rusty nail, comparison operators for vectors are separate sample functions. It is natural, while they are not used, not .

Yes, but the error is not present not because they separate smile

a guest wrote:

SFINAE it is called not.

Well, yes, SFINAE not absolutely the same. But immediately bound property.

7

Re: Compilation of templates

Anatoly Moskovsky wrote:

Yes, but errors are not present not because they separate smile

That is, those functions of template class which somewhere are caused turn out, compiled only?

8

Re: Compilation of templates

a nail wrote:

That is, those functions of template class which somewhere are caused turn out, compiled only?

Yes.

9

Re: Compilation of templates

a nail wrote:

it is passed...
That is, those functions of template class which somewhere are caused turn out, compiled only?

Yes, but changes approach and all will be possible after 20 year not so. (Units)

10

Re: Compilation of templates

MasterZiv wrote:

Yes, but changes approach and all will be possible after 20 year not so. [/quote (units)
The unit it only a syntactic tree of a piece of the code without semantic analysis of those parts which depend on template type.
They do not force  all this code - the compiler itself will select from the unit that .
Therefore with units there will be the same.

11

Re: Compilation of templates

Anatoly Moskovsky wrote:

it is passed...
The unit it only a syntactic tree of a piece of the code without semantic analysis of those parts which depend on template type.
They do not force  all this code - the compiler itself will select from the unit that .
Therefore with units there will be the same.

Hand you will give on cutting off? (It is possible to give also something another...)

12

Re: Compilation of templates

Anatoly Moskovsky wrote:

it is passed...
Well, yes, SFINAE not absolutely the same. But immediately bound property.

TIME HERE the SUBJECT of the ABM TEMPLATES And SFINAE is TYPE of the ABM TEMPLATES THEN MEANS IMMEDIATELY CONNECTED.
[spoiler] Whence substitution failure if at all any substitution does not happen anywhere??? [/spoiler]

13

Re: Compilation of templates

Whence substitution failure if at all any substitution does not happen anywhere???
SFINAE it about other generally.
This rule when at you happens  templates, and is some possible ways  (the partial specialization, or some possible signatures of functions, or some ways of type conversion and so on).
Here when the such happens, and in case of one or several ways  there is a compilation error here it just a case SFINAE , such error should not play a role, and the compiler other ways  the necessary templates should be considered.

14

Re: Compilation of templates

MasterZiv wrote:

SFINAE it about other generally.

I it also tried to inform.

15

Re: Compilation of templates

SFINAE is possible because probably not to do substitution really  functions.

Posts [ 15 ]

Pages 1

You must login or register to post a reply