boost::format and custom printing a std containers

前端 未结 4 1998
感情败类
感情败类 2020-12-30 09:51

I have a function in my namespace ns that helps me print STL containers. For example:

template 
std::ostream& operator<         


        
4条回答
  •  北海茫月
    2020-12-30 10:16

    The problem as already noted is because of ADL (argument dependent lookup - often attributed to Andrew Koenig, but I believe he shouldn't get all the blame).

    Even in your local context it wouldn't work in a template function where you intend to use your operator<<.

    One cheating trick is to put the operator<< you define into namespace std. That is verboten, but it might work in your case, but only if it is put before its usage and that might be the problem.

    There might be further options, such as defining your own Set template. I experimented with

        template using Set=std::set;
    

    but couldn't get a solution that worked without the

        using np::operator<<;
    

    yuyoyuppe provided.

提交回复
热议问题