How to avoid {} when using aggregate initialization with empty base class

前端 未结 1 1696
遇见更好的自我
遇见更好的自我 2021-01-17 21:08

C++17\'s aggregate initialization for base class is awesome, but it is verbose when the base is only there to provide some functions (so no data members).

Here is mi

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-17 21:37

    You can still provide constructor, for example:

    template  using always_t = T;
    
    struct base_pod
    {
        // functions like friend compare operator
    };
    template struct der_pod_impl;
    
    template
    struct der_pod_impl> : base_pod
    {
        der_pod_impl(always_t... args) : k{args...} {}
    
        T k[sizeof...(Is)];
    };
    
    template
    using der_pod = der_pod_impl>;
    

    Demo

    0 讨论(0)
提交回复
热议问题