C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: Partial specialization with only one template parameter in the primary template.
From: Krystian Stasiowski (sdkrystian_at_[hidden])
Date: 2019-09-28 10:05:42


I don't see how this could be specified, since the template parameters could no longer be deduced.
-------- Original message --------From: Andrew Schepler via Std-Discussion <std-discussion_at_[hidden]> Date: 9/28/19 10:24 (GMT-05:00) To: std-discussion_at_[hidden] Cc: Andrew Schepler <aschepler_at_[hidden]> Subject: Re: [std-discussion] Partial specialization with only one template parameter in the primary template. Not sure I understand. When you want to define one specific specialization like A<10>, that's what an explicit specialization is for. A partial specialization is useful when you want to define the template for some larger subset of the possible template arguments.Though C++20's constraints and concepts will actually make it possible to do partial specializations of a template like your A (without changing A to add another dummy template parameter, like the "template <int N, typename Enable=void>" technique). For example, to define A for all argument values 10 or larger:namespace N {template <int N> requires (N >= 10)struct A<N> {  A() { std::cout << "A<N>() [N>=10]\n\n"; }};}On Sat, Sep 28, 2019, 9:29 AM Vladimir Grigoriev via Std-Discussion <std-discussion_at_[hidden]> wrote:
In the Standard in teh section devoted partial specialization there is nothing said about cases when a primary template has only one template parameter. In this case sometimes it is impossible to declare a partial specialization and instead of a partial specialization we have an explicit specialization.For example#include <iostream>namespace N{ template <int> struct A { A() { std::cout << "A<int>()\n" << '\n'; } };}using N::A;namespace N{ template <> struct A<10> { A() { std::cout << "A<10>()\n" << '\n'; } };}int main(){ A<1> a1; A<10> a2;}How to define a partial specialization for template argument 10?So I think the description of the section should point out such cases. With best regards,Vlad from MoscowYou 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