3 ms·
Concerning std::allocator_traits, it reflects a deeper limitation of the language rather than just a library design flaw. If you had HKT, you could pass std::a
by dietrichepp 12y ago
Concerning std::allocator_traits, it reflects a deeper limitation of the language rather than just a library design flaw. If you had HKT, you could pass std::allocator to a template. You can't do that, you can only pass std::allocator<T> for some concrete T. Equivalently, in Haskell, you can pass IO as a type parameter, so you don't see the same kludges.
I definitely agree with the sentiment about subtype polymorphism.
- Rusky 12y agoYou can actually pass std::allocator to a template: template <class X> foo {}; template <template<class> class F> struct bar { F<int> f; }; bar<foo> b; This is painful to do with a lot of the STL like vector, because they have a lot of default template arguments and there's no implicit currying. I haven't investigated it but variadic template template arguments might help there, though.
- sjolsen 12y ago>I haven't investigated it but variadic template template arguments might help there, though. They do: template <template <typename...> class Container, typename T> Container <T> fin (T n) { Container <T> set; for (T i = 0; i < n; ++i) set.push_back (i); return set; } int main () { for (int i : fin <std::vector> (10)) std::cout << i << std::endl; }