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

后端 未结 5 1644
忘了有多久
忘了有多久 2021-02-05 10:33
  1. Is there equivalent of , in C++?

  2. Also, does ,

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-05 11:14

    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 
    #include 
    
    class Base {};
    class Derived_from_Base : public Base {};
    class Not_derived_from_Base {};
    
    template
    void workOnBase()
    {
        BOOST_STATIC_ASSERT((boost::is_base_of::value)); 
    }
    
    int main()
    {
        workOnBase();     // OK
        workOnBase(); // 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> ]

提交回复
热议问题