So I'm doing a bit of homework where I have to write my own compile-time integer sequence in C++11 and write a few functions for it (print, concat, sort etc.) but I'm having a bit of trouble wrapping my head around how I would go about writing these things.
template<typename T, typename Comp = std::less<int>>
struct Facility{
template<T ... Nums>
struct List{
struct Element<T ... nums>{};
template<unsigned num, T val, T ... rest>
struct Element{
unsigned index = num;
T value = val;
Element<index-1, rest...> others;
};
template<unsigned num, T val, T ... rest>
struct Element<0, val>{
unsigned index = 0;
T value = val;
};
static constexpr Element<Nums...> elem = {};
static void Print()
{
// Prints out the list
}
};
};
using IntList = typename Facility<int>::List<intlist...>;
int main()
{
using List1 = IntList<1, 2, 3>;
List1::print()
}
I'd just like to know if I'm on the right track so I don't work myself into a dead end. I'm not 100% sure on the static print and the static constexpr member in List, though I can't think of any other way to make it work.
Aucun commentaire:
Enregistrer un commentaire