template <bool AddOrRemoveRef>
struct Fun_;
template <>
struct Fun_<true> {
template <typename T> using type = std::add_lvalue_reference<T>;
};
template <>
struct Fun_<false> {
template <typename T> using type = std::remove_reference<T>;
};
template <typename T>
template<bool AddOrRemove>
using Fun = typename Fun_<AddOrRemove>:: template type<T>;
// question 1. I changed the two template <> postion,and got a compile error.So i really can not distinguish the sequence of two template <T> in this situation. Is there some introduction?
// template <bool AddOrRemove>
// template <typename T>
// using Fun = typename Fun_<AddOrRemove>:: template type<T>;
template <typename T> using RomoveRef = Fun<false>;
int main()
{
RomoveRef<int&>::type j = 1; // ok
printf("%d\n", j);
// question 2. I want to use Fun directly, how can i do?
// template Fun<false>::type<int&> i = 1;
// printf("%d\n", i);
return 0;
}
У меня есть два вопроса, которые написаны в комментариях в приведенном выше коде. Пожалуйста, дайте мне несколько советов, если это возможно, спасибо.
1.Как понять два шаблона <> .
2.Как использовать Fun :: type или Fun _ :: type реализовать ту же функцию, что и RomoveRef