Anonymous
i know that normal member functions are instantiated when called, not when the class itself is instantiated
Anonymous
i know that normal member functions are instantiated when called, not when the class itself is instantiated
What do you mean by "normal member functions"? 1) non-template non-static member functions of template classes 2) template non-static member functions of template classes 3) template non-static member functions of non-template class ?
Anonymous
and i'm trying to figure out about non-template static member functions of template classes
Anonymous
when are static member functions of class templates instantiated? when the class itself is instantiated? or when the function is called?
There two types of instantiations: 1) implicit (instantiate when used) examples: a) for template class: std::vector<int> vec b) for template function: foo(42); where foo is: template <typename T> foo(T val); 2) explicit a) for template function: template foo<int>(int val); I'm not sure about syntax for template classes
Anonymous
and i'm trying to figure out about non-template static member functions of template classes
Since non-template static member function of template class is not a template, you cannot use word instantiation for that
Anonymous
The actual code for that kind of member function generated when class itself is instantiated
Anonymous
The actual code for that kind of member function generated when class itself is instantiated
nope. std::vector<int> vec; won't generate code for std::vector<int>::begin(); it will only be generated when needed
Anonymous
Lippman's book
Anonymous
nope. std::vector<int> vec; won't generate code for std::vector<int>::begin(); it will only be generated when needed
My opinion is that it'll be generated anyways but if you don't call it, the compiler or linker will optimize it out
@.!
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
Lippman's book
Provide the quote please
@.!
Is there any good compiler for c++ windows 7
Anonymous
Is there any good compiler for c++ windows 7
Windows 7 is EOL, switch to Linux
Anonymous
did
I'll ask about it in Russian C++ chat
Anonymous
Dima
Switch to Linux
Anonymous
lemme advertise linux
Dima
switch to Win10 *
the worst advice ever
@.!
Switch to Linux
How I could do that?? Sorry for bothering
Anonymous
How I could do that?? Sorry for bothering
https://kubuntu.org https://spins.fedoraproject.org/kde/
Anonymous
Ok, I was wrong
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.
@.!
https://kubuntu.org https://spins.fedoraproject.org/kde/
Thankss.. but there is a question if I purchase a new laptop, what will you recommend for its operating system?
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
Because lol has no operator<
Anonymous
instantiating the function with temp<lol> will produce compile error. lol has no operator<
Anonymous
Because lol has no operator<
So instantiation of temp<lol> doesn't lead to compiler error
Anonymous
So instantiation of temp<lol> doesn't lead to compiler error
yes. which means the static member function isn't instantiated
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
No. You said temp<lol>::fun was never generated to begin with. I said it was and that the compiler deferred the error to a later point of time. This could result in either a compiler error or a linker error at a later point of time.
i'm saying temp<lol>::fn was never generated when i never used temp<lol>::fn, for example in the debian paste where the only fn() called was temp<int>::fn(test2, test2);
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
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
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