Workaround for template argument deduction in non-deduced context

后端 未结 1 1817
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 18:44

Consider the following code:

#include 

template
struct outer {
    struct inner {};
};

template
std::ostream&         


        
相关标签:
1条回答
  • 2020-11-27 19:12

    You can move the operator into the inner class body and put friend before it. Then replace the parameter type by just inner.

    Another technique is to derive inner from a CRTP base parameterized by inner. Then make the parameter type the CRTP class and cast the parameter reference to the derived inner class, the type of which is given by the template argument you deduce.

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