-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
User defined types no longer streamable #39
Comments
Could you post a complete example ? |
Sure. This used to work:
Here is the error message (truncated):
|
I also have a similar problem for my own types which are streamable to ostream. Adding overloads helps the compilation, but not sure if it is the right way to go:
|
One way around this is for example: |
For sure. But if you support the insertion operator, it stands to reason that I should be able to stream my own types via some overlading. You might want to hoist Writer out of the details::fmt namespace and make it a proper part of the API. For now, I had to revert back to an old version of spdlog since I don't have time to change all the code. |
I committed a fix - 56ee731. |
Not sure if related, but I have this new problem (that didn't happen before):
|
I think the culprit is here:
So the problem might be fixed. I'll keep compiling and see. Edit: TBH, I'm not sure why you wouldn't just cast the pointer yourself since there is nothing else the user would do. |
Looks like everything compiled and runs as expected. Thanks for the quick fix. |
Great. Thanks for reporting |
I am encountering some issues as well for custom types.
The definition of the InsertRequest is roughly this.
|
You need to implement the std::ostream& operator<< (std::ostream& o, const InsertRequest& h)
{
//You code here. Something like
//o << "Version: " << h.version <<...;
} |
Hi Gabime, Thanks for the spot, I missed out on that! |
Hi Gabime, first thanks for writing this very useful library. I tried to stream some std::vector<size_t> to a logger, but get compiler errors.
When streaming to std::cout, no issues, ie the operator<< works fine it seems. I'm not sure what I'm missing... Any suggestions would be much appreciated, System:
|
The problem is that template <typename T>
std::ostream& operator<<( std::ostream& os, const std::vector<T>& v )
^^^^^ |
why would it not recognize it if the streaming operator if it accepts a non const vector ? the error message is suggesting it is still not picking up the instantiation of operator<< for std::vector
|
Technically it is possible to recognize an overload taking non-const reference, but in this particular case I think it's better to make The error
simply means that your #include <vector>
#include <iostream>
#include <iterator>
template <typename T>
void f(const T &v) {
std::cout << v; // operator<< is not visible here because it is defined after f and it is not found by ADL
}
template <typename T>
std::ostream& operator<<( std::ostream& os, const std::vector<T>& v )
{
auto it = std::ostream_iterator<T>( os, " " );
std::copy( std::begin( v ), std::end( v ), it );
return os;
}
int main() {
std::vector<size_t> v{ 1, 2, 3, 4 };
f(v);
} To fix it either make sure that |
Hi Victor, I managed to get the stuff to compile, by putting the declaration before the including of |
I'm having problem with boost::string_ref:
Even providing a global stream operator (which I'm not sure how I would implement btw) doesn't fix the build:
Am I doing something wrong? It's the first time I try this library so I know very little about it. |
I have precisely the same problem. Has this been resolved? |
Take a look at fmts docs onchow to do it correctly (http://fmtlib.net/latest/api.html#formatting-user-defined-types) |
Not sure when this changed but my custom types are no longer streamable to the log. Is there an acceptable alternative?
The text was updated successfully, but these errors were encountered: