Cxx-prettyprint (for standard containers) defines its output operators inside namespace std - is this a standard violation?

后端 未结 1 1065
一个人的身影
一个人的身影 2020-12-20 02:10

I have been successfully using cxx-prettyprint: A C++ Container Pretty-Printer to log container values. (See also Pretty-print C++ STL containers) It\'s working lik

相关标签:
1条回答
  • 2020-12-20 02:21

    This is covered by [namespace.std]/1 in the standard (which is quoted in the question but reproducing it here as it is also the answer):

    The behavior of a C++ program is undefined if it adds declarations or definitions to namespace std or to a namespace within namespace std unless otherwise specified.

    There isn't any "otherwise specified" for overloads of operator<< for new user-defined types.

    So the behaviour is just undefined (with no diagnostic required).

    In practical terms it seems like that either the code will work or it won't, but as with all UB we should be careful not to rule anything else out.

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