How to explicitly instantiate a template for all members of MPL vector in C++?

后端 未结 6 575
日久生厌
日久生厌 2021-02-01 05:53

Consider the following header file:

// Foo.h
class Foo {
    public: 
        template 
        void read(T& value);
};

I

6条回答
  •  星月不相逢
    2021-02-01 06:22

    I've had the same requirement not long ago, and had good results with a simple function template instantiation:

    template 
    void forceInstantiation(typedef boost::mpl::vector*) {
    
        using ex = int[];
        (void)ex{(void(&Foo::read), 0)..., 0};
    
        // C++17
        // (void)((void(&Foo::read), ...));
    }
    
    template void forceInstantiation(types*);
    

提交回复
热议问题