c++ - Using pair in variadic templates -
okay, i'm trying implement range tree in n-dimensions using variadic templates. have basic setup working, want able optionally pass compare function object in template list sort tree other std::less.
my first thought overload template list version includes pair first element, pair containing type , compare funcition. can't see template declaration line compile. visual c++ (2015) starts c2079: "std::pair::first uses undefined class 't'".
anyways, on code. here's small snippet show i'm trying do:
template <class... args> class rangetree{ }; template <class t, class... args> class rangetree<t, args...> { public: map <t, rangetree<args...> * > tree; };
this works normally. when add version of rangetree, pair first template member, have problems:
template <pair<class t, class compare>, class... args> class rangetree<pair<t, compare>, args...>{ public: map <t, rangetree <args...> *, compare> tree; };
this part can seem formatted in way compiler happy. idea optionally pair template members compare functions if other less should used.
the syntax you're looking is:
template <class t, class compare, class... args> class rangetree<pair<t, compare>, args...> { ... };
alternatively, if you're doing here providing ability add comparator, can outsource work metafunction:
template <typename t> struct range_types { using key = t; using compare = std::less<t>; }; template <typename t, typename comp> struct range_types<pair<t, comp>> { using key = t; using compare = comp; }; template <class t, class... args> class rangetree<t, args...> { map <typename range_types<t>::key, rangetree <args...> *, typename range_types<t>::compare > tree; };
Comments
Post a Comment