static_assert - a way to dynamically customize error message

后端 未结 3 673
粉色の甜心
粉色の甜心 2021-01-07 21:20

Is there a way to make static_assert\'s string being dynamically customized and then displayed?
What I mean is something like:

//pseudo code
static_ass         


        
3条回答
  •  遥遥无期
    2021-01-07 22:27

    As Matthieu said, it's not possible, but you can get some of the functionalities you're looking for by using macros:

    #define CHECK_TYPE_RANGE(type)\
        static_assert(Check_Range::value, "Value of " #type " type is not so good ;)");
    
    CHECK_TYPE_RANGE(float); // outputs "Value of float type is not so good ;)"
    

提交回复
热议问题