Частичная специализация шаблона класса для константных и неконстантных указателейC++

Программы на C++. Форум разработчиков
Ответить Пред. темаСлед. тема
Anonymous
 Частичная специализация шаблона класса для константных и неконстантных указателей

Сообщение Anonymous »


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
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Частичная специализация шаблона класса с нетиповым параметром шаблона decltype(auto)
    Anonymous » » в форуме C++
    0 Ответы
    63 Просмотры
    Последнее сообщение Anonymous
  • Элегантное решение для дублирования, константных и неконстантных геттеров? [дубликат]
    Гость » » в форуме C++
    0 Ответы
    32 Просмотры
    Последнее сообщение Гость
  • Частичная специализация шаблона вариативного шаблона C++ с помощью std::enable_if
    Anonymous » » в форуме C++
    0 Ответы
    25 Просмотры
    Последнее сообщение Anonymous
  • Частичная специализация шаблона шаблона
    Anonymous » » в форуме C++
    0 Ответы
    25 Просмотры
    Последнее сообщение Anonymous
  • Частичная специализация с использованием концепций
    Anonymous » » в форуме C++
    0 Ответы
    7 Просмотры
    Последнее сообщение Anonymous

Вернуться в «C++»