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 two directly, how can i do?
// template Fun<false>::type<int&> i = 1;
// printf("%d\n", i);
return 0;
}
I have two questions which are written in comments part in above code.Please give me some suggestions if it is possible,thank you.
1.How to understand the two template <> postion. 2.How to use Fun::type or Fun_::type implement the same function as RomoveRef
Aucun commentaire:
Enregistrer un commentaire