C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: C++ 20: Member templates. Is there a typo in the following example?
From: Will Hawkins (hawkinsw_at_[hidden])
Date: 2019-08-23 21:28:54


Why wouldn't the call

ac.f('c')

implicitly instantiate the member function template for T2 = char?
Because they are all in the same translation unit, that seems to be,
in my understanding, what would happen in this case.

Of course, I haven't put this in a compiler, so I could be completely mistaken.

Will

On Wed, Aug 21, 2019 at 11:41 AM Vladimir Grigoriev via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
> In the p.#2 of the section "13.6.2 Member templates" there is the following example
>
> template <class T>struct A {
> void f(int);
> template <class T2> void f(T2);
> };
>
> template <> void A<int>::f(int) { } // non-template member function
> template <> template <> void A<int>::f<>(int) { } // member function template specialization
>
> int main() {
> A<char> ac;
> ac.f(1); // non-template
> ac.f(’c’); // template
> ac.f<>(1); // template
> }
>
> However there is no definition for example for the specialization of the non-template function for A<char>. So the code is invalid. That is the compiler will issue an error.
>
> Should the template specializations be done in this example for A<char> instead of A<int>?
>
> With best regards,
> Vlad from Moscow
>
> You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion


STD-DISCUSSION list run by herb.sutter at gmail.com

Older Archives on Google Groups