Anonymous
i know that normal member functions are instantiated when called, not when the class itself is instantiated
Anonymous
Anonymous
and i'm trying to figure out about
non-template static member functions of template classes
Anonymous
The actual code for that kind of member function generated when class itself is instantiated
Anonymous
Anonymous
Lippman's book
Anonymous
@.!
Is there any good compiler for c++ windows 7
Anonymous
by default, a member function of a class template is instantiated only if the program uses that member function. For example, this code
// instantiates Blob<int> and the initializer_list<int> constructor
Blob<int> squares = {0,1,2,3,4,5,6,7,8,9};
// instantiates Blob<int>::size() const
for (size_t i = 0; i != squares.size(); ++i)
squares[i] = i*i; // instantiates Blob<int>::operator[](size_t)
instantiates the Blob<int> class and three of its member functions: operator[], size, and the initializer_list<int> constructor.
If a member function isn’t used, it is not instantiated. The fact that members are instantiated only if we use them lets us instantiate a class with a type that may not meet the requirements for some of the template’s operations (§ 9.2, p. 329).
By default, a member of an instantiated class template is instantiated only if the member is used.
Anonymous
@.!
Is there any good compiler for c++ windows 7
Anonymous
Anonymous
did
I'll ask about it in Russian C++ chat
Anonymous
Anonymous
Anonymous
Dima
Switch to Linux
Anonymous
lemme advertise linux
Anonymous
by default, a member function of a class template is instantiated only if the program uses that member function. For example, this code
// instantiates Blob<int> and the initializer_list<int> constructor
Blob<int> squares = {0,1,2,3,4,5,6,7,8,9};
// instantiates Blob<int>::size() const
for (size_t i = 0; i != squares.size(); ++i)
squares[i] = i*i; // instantiates Blob<int>::operator[](size_t)
instantiates the Blob<int> class and three of its member functions: operator[], size, and the initializer_list<int> constructor.
If a member function isn’t used, it is not instantiated. The fact that members are instantiated only if we use them lets us instantiate a class with a type that may not meet the requirements for some of the template’s operations (§ 9.2, p. 329).
By default, a member of an instantiated class template is instantiated only if the member is used.
and this was the page 329 quote that the section mentioned
Although we can store almost any type in a container, some container operations impose requirements of their own on the element type. We can define a container for a type that does not support an operation-specific requirement, but we can use an operation only if the element type meets that operation’s requirements.
@unterumarmung
Anonymous
Ok, I was wrong
Anonymous
by default, a member function of a class template is instantiated only if the program uses that member function. For example, this code
// instantiates Blob<int> and the initializer_list<int> constructor
Blob<int> squares = {0,1,2,3,4,5,6,7,8,9};
// instantiates Blob<int>::size() const
for (size_t i = 0; i != squares.size(); ++i)
squares[i] = i*i; // instantiates Blob<int>::operator[](size_t)
instantiates the Blob<int> class and three of its member functions: operator[], size, and the initializer_list<int> constructor.
If a member function isn’t used, it is not instantiated. The fact that members are instantiated only if we use them lets us instantiate a class with a type that may not meet the requirements for some of the template’s operations (§ 9.2, p. 329).
By default, a member of an instantiated class template is instantiated only if the member is used.
This is true
Anonymous
by default, a member function of a class template is instantiated only if the program uses that member function. For example, this code
// instantiates Blob<int> and the initializer_list<int> constructor
Blob<int> squares = {0,1,2,3,4,5,6,7,8,9};
// instantiates Blob<int>::size() const
for (size_t i = 0; i != squares.size(); ++i)
squares[i] = i*i; // instantiates Blob<int>::operator[](size_t)
instantiates the Blob<int> class and three of its member functions: operator[], size, and the initializer_list<int> constructor.
If a member function isn’t used, it is not instantiated. The fact that members are instantiated only if we use them lets us instantiate a class with a type that may not meet the requirements for some of the template’s operations (§ 9.2, p. 329).
By default, a member of an instantiated class template is instantiated only if the member is used.
oh wait i can test this by putting conditions in the static member function and trying to initialise the class template with a class that doesn't have the condition
Anonymous
The reason to this kind of behavior is providing ability for example to instantiate a vector of non-copyable and non-movable type. You can use this vector but the resize member will not be instantiated.
Anonymous
no i just tested. even static non-template member functions are instantiated when used.
Anonymous
https://paste.debian.net/hidden/a003f2d4/
no compile error
Anonymous
only replacing temp<int>::fn with temp<lol>::fn or adding a line for temp<lol>::fn causes compile error
Anonymous
Anonymous
Because lol has no operator<
Anonymous
instantiating the function with temp<lol> will produce compile error. lol has no operator<
Anonymous
Anonymous
Yes
Anonymous
"but not of the definitions or default arguments, of the class member functions, member classes, static data members and member templates;"
my question was if "class member functions" included static member functions
Anonymous
ye
Anonymous
I know how SFINAE works :D
Anonymous
I got it
Anonymous
i looked at the wikipedia page for SFINAE and tried some examples, it seems like it is about the "causes the implicit instantiation of the declarations" part of the standard you quoted. "The implicit instantiation of a class template specialization causes the implicit instantiation of the declarations, but not of the definitions or default arguments,"
i was talking about the instantiation of the definition/function body than the declaration
Anonymous
but anyway
Anonymous
this is the answer i was looking for
Anonymous
oh, yes i did base my previous answer based on the "missing type member of some class" examples on the wikipedia page
Anonymous
but even then, the expression SFINAE thing on cppreference mentions
The following expression errors are SFINAE errors
Ill-formed expression used in a template parameter type
Ill-formed expression used in the function type
Anonymous
my ill-formed expression was in the function body
Anonymous
but how would the compiler instantiate a function that contains an ill-formed expression?
Anonymous
once again, i'm talking about instantiating the function definition
🐉
Quick question: I'm making a Hotel Management Exercise using OOP.
Hotel Management gots a list of free Rooms and a list of Prenotations, pointing to a room when prenoted;
Should I make an abstract class Room, and then 3 derived class single double and triple, so I can add more typologies later on, and create Room pointers to single/double/triple or should I go for simple inheritance?
Anonymous
lemme rephrase what i understand you are saying and what i am saying
you are saying that the code for temp<lol>::fn() was generated when i did
temp<lol> test2;
only there was a blank for the location of operator< in the code.
the compiler tried to fill the blank only when i did fn(test2, test2) and that is why i got the error when doing this but not when i left out any usage of temp<lol>::fn()
i am saying that an attempt to generate the entire code for temp<lol>::fn() failed when i called fn(test2, test2); and not before that. this is why i did get the error when doing this but not when i left out usages of temp<lol>::fn();
Anonymous
a way to test this could be checking the sizes of the binary when the temp<int>::fn() is never called and when it is called. i will try that in debug mode
Anonymous
Anonymous
Anonymous
"So the compiler defers the error to the existence of this function at the point where this operator is used rather than at the point where the instantiation is done."
i thought by this you meant that if temp<lol>::fn() is 10 lines in assembly and the call to operator< of lol is at line 3, lines 1-2, 4-10 are generated when instantiating temp<lol> during the temp<lol> test; line. the third line is filled when fn(test, test); is called
🐉
ty
Anonymous
"My point is that the standard doesn't imply this"
but what about this part in your quote from the standard
the implicit instantiation of the declarations, but not of the definitions or default arguments, of the class member functions
Anonymous
declaration is instantiated, but not the definition
Anonymous
oh
Anonymous
Anonymous
if static class member functions are a subset of class member functions in that statement
Anonymous
thanks
Anonymous
yes. but i thought that static member functions are a subset of class member functions, so they won't need separate mention.
Anonymous
but clearly they are not.
Anonymous
oh
Anonymous
no i think i was right. static member functions are a subset of member functions
11.4.8.1 Static member functions [class.static.mfct]
1 [Note: The rules described in 11.4.1 apply to static member functions. — end note]
the rules in 11.4.1 are about class member functions
the rules special to non-static member functions are in 11.4.2
Anonymous
so since "non-static member functions" is not explicitly mentioned and "class member functions" is used, this probably applies to static member functions as well
Anonymous
Anonymous
oh. the C++20 draft has been finalised already
Anonymous
here
Anonymous
Anonymous
the title of 11.4.1 is Member functions, the first line of the first paragraph is
"A member function may be defined (9.5) in its class definition,..."
if the rules described in 11.4.1 apply to static member functions as said in 11.4.8.1 paragraph 1, that makes a static member function a member function by definition
Anonymous
also, since non-static member functions are defined separately in 11.4.2, my argument about
"so since "non-static member functions" is not explicitly mentioned and "class member functions" is used, this probably applies to static member functions as well"
still stands
Anonymous
it doesn't imply a non-static member function. that is why 11.4.2 is a separate section from 11.4.1
Anonymous
i believe those are the same given section 11.4 is titled "Class members" and 11.4.1 is titled "Member functions"
Anonymous
how are you asserting that a class member function implies a non-static member function