Closed ddevienne closed 3 years ago
That's not a Boost.Describe requirement, it's how C++ works; for op<< to be found it needs to be in an associated namespace of the class. It's not possible for users to legally define op<< for std::map (at least not in the general case) because they don't own the type; the standard library does.
For std::map<std::string, My::Inner>
you can provide it in namespace My
and it should work.
That's also the reason the library can't provide the universal print function; it also needs to go into namespace My
in order to apply to described types in My
, otherwise it won't be found.
I tried that, and it didn't work. But I may have funged it. I'll retry it later, possibly on a shorter example. As of now, I'm stuck.
I moved the << operators into namespace My
, fixed the errors, and it worked: https://gist.github.com/pdimov/a10562499e346cda712472c3cdef2d47
(that is, it compiled, didn't link because there's no definition of to_string
for map
, as it's "provided elsewhere".)
Thanks Peter! Problem is, the generated types are in different namespaces, so does that mean the utilities formerly in the describe_utils namespace need to be duplicated in the std::map|vector|etc... using class namespaces? That would also mean they cannot be provided generically by Boost.Describe itself, as several reviewers asked as well?
BTW, I had trouble with op<<, but not with op==, on the same types. That compiled fine. So what's special about op<<, to require the describe-using templates and the described types to be in the same NS?
That would also mean they cannot be provided generically by Boost.Describe itself, as several reviewers asked as well?
Yes, it's not possible to provide an operator generically. It must be in an associated namespace.
So what's special about op<<, to require the describe-using templates and the described types to be in the same NS?
Nothing is special about op<<. op== should have the same problem. I don't know why it worked, but the general case is much the same. E.g. https://gist.github.com/pdimov/ed7b17497211aae9cdf55b4e04179ee9 fails when the generic op== is not in namespace app
.
Closing this, as not really an issue with the library itself.
There is no op<< for std::map. The universal printing example requires one.
Trouble is, Boost.Describe seems to require it in the std namespace, except of course that's illegal to add to std, except for specializations. (I'm no expect, but I know that one). I cannot share the exact code that fails for me, since it's part of a large code-generated library, but essentially it boils down to what's below.
With it's illegal op<< for the instantiated map template for <string, My::Inner>, this builds fine on MSVC 2019, C++17. I did not even try providing a templated one, to simply my testing.
I realize it's not the best of report, but hopefully you can see the big picture, and perhaps even prove me wrong via a simple example.
Here's the error I get, if not using that illegal std op<<. I put it in a different namespace, like the local anon one, or another in-scope, similar error each time.