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

I think you can get something similar now with C++20 concepts?

    template<typename T, typename U>
    void my_func(std::vector<T>* vec) requires std::derived_from<T, my_data_container<U>>;
(Probably mangled something, but the idea is there)

Without concepts, you're left with SINFAE:

    template<typename T, typename U, typename = std::enable_if_t<std::is_base_of_v<my_data_container<U>, T>>>
    void my_func(std::vector<T>* vec);
or just a regular function and a hope that anything wrong will be caught by the compiler:

    template<typename T, typename U>
    void my_func(std::vector<T>* vec) {
        // use my_data_container<U> somewhere and hope things blow up if something is wrong
        // Not 100% sure this is allowed, but something similar should be at least
    }


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

Search: