C++ type registration at compile time trick

前端 未结 3 1666
梦毁少年i
梦毁少年i 2020-11-30 04:25

I have the following situation: suppose I have a bunch of types (functors) which I want to register/compile in during compilation, preferably into something like boost::mpl:

3条回答
  •  既然无缘
    2020-11-30 04:51

    You'll never solve the mpl::vector idea. You can't alter template "variables". Remember that template metaprogramming is a PURE functional language. No side effects at all.

    As for registering...the macro thing works fine. Define the macro so that it declares and initializes some small global variable with the registration process. Alternatively you can go down the road I did here:

    How to force inclusion of "unused" object definitions in a library

    Note the fix if you're trying to do it in a library.

提交回复
热议问题