Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You 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.



>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;
    }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: