How to do static_assert with macros?

后端 未结 5 2091
温柔的废话
温柔的废话 2020-12-02 01:27

I have tried to use this suggestion to do a static assert, but I do not get a compilation error if I use it within a method of a template.

The example follows :

5条回答
  •  情歌与酒
    2020-12-02 02:03

    Prior to C++11 I would normally do:

    typedef int static_assert_something[something ? 1 : -1];
    

    You can also look at boost static assert. But it is too bloated for my liking. It is easy to make things bigger, it is hard to make them any better.

提交回复
热议问题