Is there equivalent of <? extends T>, <? super T> in C++?

c++, generics, java, templates

Solution

It doesn't have quite nice syntactic sugar as in Java but it's manageable well with boost/type_traits . See http://www.boost.org/doc/libs/1_40_0/libs/type_traits/doc/html/index.html for more info.

#include <boost/type_traits.hpp>
#include <boost/static_assert.hpp>

class Base {};
class Derived_from_Base : public Base {};
class Not_derived_from_Base {};

template<typename BASE, typename DERIVED>
void workOnBase()
{
    BOOST_STATIC_ASSERT((boost::is_base_of<BASE, DERIVED>::value)); 
}

int main()
{
    workOnBase<Base, Derived_from_Base>();     // OK
    workOnBase<Base, Not_derived_from_Base>(); // FAIL
    return 0;
}

1>d:...\main.cpp(11) : error C2027: use of undefined type 'boost::STATIC_ASSERTION_FAILURE' 1> with 1> [ 1> x=false 1> ]

Problem

Is there equivalent of `<? extends T>`, `<? super T>` in C++? Also, does `<? extends T>`, `<? super T>` work even if `T` is an interface in Java?

Original source

Related problems