Skip to content
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

Visual Studio picks up internal std::ostream despite including fmt/ostream.h #2294

Closed
zcream opened this issue May 18, 2021 · 1 comment
Closed

Comments

@zcream
Copy link

zcream commented May 18, 2021

I have #include <fmt/ostream.h> in my program.
Yet a compile with Visual Studio picks up the internal version of std::ostream for this code.

EDIT:- A similar problem is described here #1261

@vitaut suggested I think that the problem is that your operator<< is not visible in fmt/ostream.h where the formatter is specialized. You can fix this by moving the operator to a header which is included before fmt/ostream.h or use fmt/ranges.h that provides formatting support for containers and ranges.

How do we manage this for classes ?

friend std::ostream& operator<<(std::ostream& out, const EmailAddress& email)
    {
        return out << email.name_ << " " << email.email_;
    }
typedef std::vector<EmailAddress> EmailAddresses;
std::ostream& operator<<(std::ostream& out, const EmailAddresses& emailAddresses);

And this is how the code is being used

  out << addrs.front();
  for (auto it = addrs.begin() + 1; it != addrs.end(); ++it) {
    out << "," << *it;
  }
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\ostream(746,1): 
warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc

The enable C++exception is not important, what I am concerned with is the use of the internal ostream.

@zcream zcream changed the title Visual Studio picks up internal std::ostream despite includinf fmt/ostream.h Visual Studio picks up internal std::ostream despite including fmt/ostream.h May 18, 2021
@vitaut
Copy link
Contributor

vitaut commented May 18, 2021

operator<< must be discoverable by ADL for it to work with formatting functions. If this is not possible you can define a formatter specialization instead as explained in #2130 (comment).

@vitaut vitaut closed this as completed May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants