Enforce template type through static_assert

前端 未结 3 697
梦如初夏
梦如初夏 2021-02-12 14:40

I\'m trying to understand the usefulness of static_assert, and I want to know if it can help me in enforcing a design, and if so, how.

I have a general temp

3条回答
  •  故里飘歌
    2021-02-12 15:21

    http://en.cppreference.com/w/cpp/header/type_traits

    std::is_base_of and std::is_convertible could help with your first issue and as for the second,

    static_assert(!std::is_same(),"type can't be float");

    hopefully this helps someone else who stumbles upon this question, assuming OP probably found an answer in the 4 years since it was asked :)

提交回复
热议问题