14.7.1.(9) from the C++ standard

  • Thread starter subramanian100in
  • Start date
S

subramanian100in

14.7.1.(9) from the C++ standard: "An implementation shall not
implicitly instantiate a function template, a member template, a
nonvirtual member function, a member class or a static data member of
a class template that does not require instantiation"

Here, what does 'member template' mean ?

In the above statement, kindly explain the line(if possible please
give an example)
"a member class or a static data member of a class template that does
not require instantiation"

Thanks
V.Subramanian
 
V

Victor Bazarov

14.7.1.(9) from the C++ standard: "An implementation shall not
implicitly instantiate a function template, a member template, a
nonvirtual member function, a member class or a static data member of
a class template that does not require instantiation"

Here, what does 'member template' mean ?

template<class T> class A {}; // class template
template<class T> void foo(T); // function template
template<class T> class B {
void foo(); // non-virtual function
static int i; // data member
template<class T> int blah(); // member template
In the above statement, kindly explain the line(if possible please
give an example)
"a member class or a static data member of a class template that does
not require instantiation"

If the class template that doesn't require instantiation (never used
in the program in such way that would cause instantiation), a member
template of that class [template] and other elements that are really
templates, shouldn't require instantiation either. To keep the code
from being bloated from the unnecessary instantiations of the class
members the Standard explicitly prohibits those. At least that's how
I read it.

V
 
B

Bo Persson

Victor Bazarov wrote:
:: (e-mail address removed) wrote:
::: 14.7.1.(9) from the C++ standard: "An implementation shall not
::: implicitly instantiate a function template, a member template, a
::: nonvirtual member function, a member class or a static data
::: member of a class template that does not require instantiation"
:::
::: Here, what does 'member template' mean ?
::
:: template<class T> class A {}; // class template
:: template<class T> void foo(T); // function template
:: template<class T> class B {
:: void foo(); // non-virtual function
:: static int i; // data member
:: template<class T> int blah(); // member template
:: template<class T> class S {}; // member template
:: };
::
::: In the above statement, kindly explain the line(if possible please
::: give an example)
::: "a member class or a static data member of a class template that
::: does not require instantiation"
::
:: If the class template that doesn't require instantiation (never
:: used in the program in such way that would cause instantiation), a
:: member template of that class [template] and other elements that
:: are really templates, shouldn't require instantiation either. To
:: keep the code from being bloated from the unnecessary
:: instantiations of the class members the Standard explicitly
:: prohibits those. At least that's how I read it.
::

It also saves you from the problem that some members, like perhaps
foo(), cannot be instantiated for all T's. This is not an error,
unless someone actually calls foo() for that T.


Bo Persson
 
W

werasm

template<class T> class A {}; // class template
template<class T> void foo(T); // function template
template<class T> class B {
void foo(); // non-virtual function
static int i; // data member
template<class T> int blah(); // member template
template<class T> class S {}; // member template
};

I'm not sure what the standard says, but the code here
above does not compile on GCC 4+ as well as Comeau
online.

"ComeauTest.c", line 7: error:
template parameter "T" may not be redeclared in this scope

template<class T> class S {}; // member template

where scope is the scope of B. Code below fixed this - maybe
the mistake is just a small oversight.

template<class T> class B {
void foo(); // non-virtual function
static int i; // data member
template<class U> int blah(); // member template
template<class U> class S {}; // member template
};

Regards,

Werner
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,197
Messages
2,571,040
Members
47,634
Latest member
RonnyBoelk

Latest Threads

Top