Частичная специализация шаблона класса для константных и неконстантных указателей ⇐ C++
Частичная специализация шаблона класса для константных и неконстантных указателей
I am trying to make a class template with non-type template parameter of pointer type, which has two specializations for const and not-const pointers.
This is my best attempt, accepted by Clang and GCC:
template struct A {}; template struct A; int v; A a; but A still uses the primary template with const pointer despite &v has type int*.
On the other hand, MSVC prints:
error C2753: 'A': partial specialization cannot match argument list for primary template Online demo: https://godbolt.org/z/EzoYoxEza
Is my partial specialization correct? And if yes, how can I use A?
Another attempt was to declare the primary template with auto non-type template parameter and specialize it twice:
template struct A; template struct A {}; template struct A; int v; A a; It works fine with GCC, but both Clang and MSVC complain:
Clang error: ambiguous partial specializations of 'A' MSVC error C2752: 'A': more than one partial specialization matches the template argument list Online demo: https://godbolt.org/z/43bj6EWq6
Considering that all compilers agreed in the previous example that template is more specialized than template , which one is correct here?
Источник: https://stackoverflow.com/questions/777 ... t-pointers
I am trying to make a class template with non-type template parameter of pointer type, which has two specializations for const and not-const pointers.
This is my best attempt, accepted by Clang and GCC:
template struct A {}; template struct A; int v; A a; but A still uses the primary template with const pointer despite &v has type int*.
On the other hand, MSVC prints:
error C2753: 'A': partial specialization cannot match argument list for primary template Online demo: https://godbolt.org/z/EzoYoxEza
Is my partial specialization correct? And if yes, how can I use A?
Another attempt was to declare the primary template with auto non-type template parameter and specialize it twice:
template struct A; template struct A {}; template struct A; int v; A a; It works fine with GCC, but both Clang and MSVC complain:
Clang error: ambiguous partial specializations of 'A' MSVC error C2752: 'A': more than one partial specialization matches the template argument list Online demo: https://godbolt.org/z/43bj6EWq6
Considering that all compilers agreed in the previous example that template is more specialized than template , which one is correct here?
Источник: https://stackoverflow.com/questions/777 ... t-pointers
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Частичная специализация шаблона класса с нетиповым параметром шаблона decltype(auto)
Anonymous » » в форуме C++ - 0 Ответы
- 63 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Частичная специализация шаблона вариативного шаблона C++ с помощью std::enable_if
Anonymous » » в форуме C++ - 0 Ответы
- 25 Просмотры
-
Последнее сообщение Anonymous
-