Minor edition in 17 Templates

1,758 views
Skip to first unread message

Vlad from Moscow

unread,
May 28, 2019, 8:47:19 AM5/28/19
to ISO C++ Standard - Discussion
In the C++ Standard 17 in the section 17 Templates (p. #2) there is written

(2.3) — define a member template of a class or class template, or

Should it be written instead?

(2.3) — declare or define a member template of a class or class template, or 


Jens Maurer

unread,
May 28, 2019, 1:58:23 PM5/28/19
to ISO C++ Standard - Discussion

No, it's correct as-is. This covers the case where there are multiple
nested template-heads, e.g.

template<class T>
template<class U>
void S<T>::f(U) { }

In such a case, the /declaration/

template<class U>
void S<T>::f(U) { }

must be a definition. (You can't just-declare member functions outside
of their class.)

Jens
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to std-discussio...@isocpp.org <mailto:std-discussio...@isocpp.org>.
> To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-discussion/9bd96841-9211-44f3-8272-8dd1ac63abdf%40isocpp.org <https://groups.google.com/a/isocpp.org/d/msgid/std-discussion/9bd96841-9211-44f3-8272-8dd1ac63abdf%40isocpp.org?utm_medium=email&utm_source=footer>.

Vlad from Moscow

unread,
May 30, 2019, 7:38:00 AM5/30/19
to ISO C++ Standard - Discussion
Consider an example

#include <iostream>


struct A
{
   
template <auto N>
   
static void f(); // template member declaration
};


template <auto N>
void A::f() { std::cout << N << '\n'; } // template member definition


int main()
{
    A
::f<10>();
    A
::f<'A'>();
}



What is wrong with this example?

Here there are a declaration of a template member (without its definition) inside a non-template class and a definition of a template member outside a non-template class.

вторник, 28 мая 2019 г., 20:58:23 UTC+3 пользователь Jens Maurer написал:

No, it's correct as-is.  This covers the case where there are multiple
nested template-heads, e.g.

template<class T>
template<class U>
void S<T>::f(U) { }

In such a case, the /declaration/

template<class U>
void S<T>::f(U) { }

must be a definition. (You can't just-declare member functions outside
of their class.)

Jens


On 28/05/2019 14.47, 'Vlad from Moscow' via ISO C++ Standard - Discussion wrote:
> In the C++ Standard 17 in the section 17 Templates (p. #2) there is written
>
>     (2.3) — define a member template of a class or class template, or
>
>
> Should it be written instead?
>
>     (2.3) — declare or define a member template of a class or class template, or 
>
>
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to std-dis...@isocpp.org <mailto:std-discussion+unsub...@isocpp.org>.

Jens Maurer

unread,
May 30, 2019, 1:46:27 PM5/30/19
to std-dis...@isocpp.org

The sentence is talking about the "/declaration/ in a /template-declaration/".

The /template-declaration/ is

template<auto N>
static void f();

The contained /declaration/ is

"static void f();"

which is a function declaration (first bullet).

Jens


On 30/05/2019 13.38, 'Vlad from Moscow' via ISO C++ Standard - Discussion wrote:
> Consider an example
>
> |
> #include<iostream>
>
>
> structA
> {
>     template<autoN>
>     staticvoidf();// template member declaration
> };
>
>
> template<autoN>
> voidA::f(){std::cout <<N <<'\n';}// template member definition
> > To unsubscribe from this group and stop receiving emails from it, send an email to std-dis...@isocpp.org <javascript:> <mailto:std-discussio...@isocpp.org <javascript:>>.
> > To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-discussion/9bd96841-9211-44f3-8272-8dd1ac63abdf%40isocpp.org <https://groups.google.com/a/isocpp.org/d/msgid/std-discussion/9bd96841-9211-44f3-8272-8dd1ac63abdf%40isocpp.org> <https://groups.google.com/a/isocpp.org/d/msgid/std-discussion/9bd96841-9211-44f3-8272-8dd1ac63abdf%40isocpp.org?utm_medium=email&utm_source=footer <https://groups.google.com/a/isocpp.org/d/msgid/std-discussion/9bd96841-9211-44f3-8272-8dd1ac63abdf%40isocpp.org?utm_medium=email&utm_source=footer>>.
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to std-discussio...@isocpp.org <mailto:std-discussio...@isocpp.org>.
> To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-discussion/48bd77ec-b756-440d-8ee9-208c03cfc719%40isocpp.org <https://groups.google.com/a/isocpp.org/d/msgid/std-discussion/48bd77ec-b756-440d-8ee9-208c03cfc719%40isocpp.org?utm_medium=email&utm_source=footer>.

Vlad from Moscow

unread,
May 31, 2019, 9:53:50 AM5/31/19
to ISO C++ Standard - Discussion
O'k. I have understood. Thanks.

четверг, 30 мая 2019 г., 20:46:27 UTC+3 пользователь Jens Maurer написал:
>     > To unsubscribe from this group and stop receiving emails from it, send an email to std-dis...@isocpp.org <javascript:> <mailto:std-discussion+unsub...@isocpp.org <javascript:>>.
> To unsubscribe from this group and stop receiving emails from it, send an email to std-dis...@isocpp.org <mailto:std-discussion+unsub...@isocpp.org>.

Vlad from Moscow

unread,
Jun 28, 2019, 10:03:16 AM6/28/19
to ISO C++ Standard - Discussion
However this just confuses readers.

There are three categories of template declarations.

  1. standalone templates
  2. members of class templates
  3. templates of a class or a class template 

So this paragraph should describe all three categories separately. and relative to templates of a class or class templates there should be written

(2.3) — declare or define a member template of a class or class template, or 

четверг, 30 мая 2019 г., 20:46:27 UTC+3 пользователь Jens Maurer написал:
>     > To unsubscribe from this group and stop receiving emails from it, send an email to std-dis...@isocpp.org <javascript:> <mailto:std-discussion+unsub...@isocpp.org <javascript:>>.
> To unsubscribe from this group and stop receiving emails from it, send an email to std-dis...@isocpp.org <mailto:std-discussion+unsub...@isocpp.org>.
Reply all
Reply to author
Forward
0 new messages