Действительно ли возможно получить доступ к значениям шаблонных параметров нетипа в специализированном шаблонном классе?

  1. Переходят в Targets в Xcode
  2. Get Info на цели Вашего проекта (Ваше текущее имя разработки)
  3. Поиск Product Name под Packaging. Измените значение того, чем Вы хотите, чтобы Ваше новое название проекта было.
10
задан stefanB 22 July 2009 в 00:08
поделиться

2 ответа

Проблема такого рода может быть решена с помощью отдельного набора структур "Traits".

// A default Traits class has no information
template<class T> struct Traits
{
};

// A convenient way to get the Traits of the type of a given value without
// having to explicitly write out the type
template<typename T> Traits<T> GetTraits(const T&)
{
    return Traits<T>();
}

template <int major, int minor> struct A 
{ 
    void f() 
    { 
        cout << major << endl; 
    }   
};

// Specialisation of the traits for any A<int, int>
template<int N1, int N2> struct Traits<A<N1, N2> >
{
    enum { major = N1, minor = N2 };
};

template <> struct A<4,0> 
{       
    void f() 
    { 
        cout << GetTraits(*this).major << endl; 
    }   
};
16
ответ дан 3 December 2019 в 21:22
поделиться

Не совсем ответ на ваш вопрос, но вы можете перечислить их, а именно:

enum{
 specialisationMajor=4,
 specialisationMinor=0
};

template <> struct A<specialisationMajor,specialisationMinor> {
    static const int major = specialisationMajor;
    static const int minor = specialisationMinor;
    ...
}
1
ответ дан 3 December 2019 в 21:22
поделиться
Другие вопросы по тегам:

Похожие вопросы: