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

formatting/printing vector of quantities results in compile time error #543

Closed
WBurzynski opened this issue Jan 14, 2024 · 3 comments · Fixed by #548
Closed

formatting/printing vector of quantities results in compile time error #543

WBurzynski opened this issue Jan 14, 2024 · 3 comments · Fixed by #548
Labels
bug Something isn't working

Comments

@WBurzynski
Copy link

WBurzynski commented Jan 14, 2024

Not sure if It's this library bug or fmt, but trying to print vector of quantity results in compile time error.

Problem reproduced in compiler explorer:

https://godbolt.org/z/7v5jjh9Gs

Problematic code:

#include <mp-units/systems/si/si.h>
#include <vector>
#include "fmt/ranges.h"
#include "mp-units/format.h"
#include "fmt/format.h"


using namespace mp_units::si::unit_symbols;

int main()
{
    using Time = mp_units::quantity<mp_units::isq::time[mp_units::si::second]>;
    Time time = 1 * s;
    fmt::println("{}",time);
    std::vector<Time> vec{time,time};
    fmt::println("{}",vec);
}
@mpusz
Copy link
Owner

mpusz commented Jan 15, 2024

@WBurzynski, thanks for reporting! This seems to be related to #503. Initially, the fmtlib did not require the format() member function to be const, and this was how they implemented their own formatters. However, during the standardization process, this member function became const, and fmtlib updated the support in the next releases. mp-units stayed behind.

I actually started to work on this issue during the weekend, and hopefully, it will be fixed soon.

@mpusz mpusz added the bug Something isn't working label Jan 15, 2024
@WBurzynski
Copy link
Author

Some time ago there was this issue in fmt: fmtlib/fmt#2754 where const qualifiers were added to some functions. I suspect that either somewhere in fmt another const is missing or in auto format(const quantity& q, FormatContext& ctx) const quantity is too restrictive.

@mpusz
Copy link
Owner

mpusz commented Jan 15, 2024

No, the problem is that the member function format() should be const qualified, but it isn't. It was changed while fmt was standardized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants