Identifying primitive types in templates

后端 未结 8 859
南旧
南旧 2020-11-27 17:40

I am looking for a way to identify primitives types in a template class definition.

I mean, having this class :

template
class A{
void         


        
8条回答
  •  醉酒成梦
    2020-11-27 18:25

    It cannot be done exactly the way you asked. Here is how it can be done :

    template
    class A{
    void doWork(){
       bool isPrimitive = boost::is_fundamental::value;
       if(isPrimitive)
         doSomething();
       else
         doSomethingElse(); 
    }
    private:
    T *t; 
    };
    

    You may get a warning if you put the value of isPrimitive directly inside the if statement. This is why i introduced a temporary variable.

提交回复
热议问题