How can I make compile time assertions without C++11

前端 未结 3 2017
囚心锁ツ
囚心锁ツ 2021-02-06 00:10

In a job interview, I was asked to write a metafunction that determined whether a type was a pointer. This is what I presented:

template 
struc         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-06 00:43

    In your case

    template  struct assert;
    template <> struct assert {};
    

    would have solved the problem:

    assert::value>();     // valid
    assert::value>();    // valid
    
    assert::value>();      // compilation error:
                                            // use of incomplete class
    

提交回复
热议问题