by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    gerald5867
    @gerald5867
    i did made an issue and closed it again because i wanted to ask first if im doing something wrong.
    i did reopen it just now
    Giulio De Pasquale
    @peperunas
    @vitaut hello Victor, I am following your suggestion to create a custom formatter for LLVM's MachineInstr. I am receiving this error (since I'm using C++11): function uses ‘auto’ type specifier without trailing return type. Which return type should I put instead of auto?
    Here's my sample code:
    template <> struct fmt::formatter<llvm::MachineInstr> {
      template <typename ParseContext> constexpr auto parse(ParseContext &ctx) {
        return ctx.begin();
      }
    
      template <typename FormatContext>
      auto format(const llvm::MachineInstr &MI, FormatContext &ctx) {
        return fmt::format_to(ctx.begin(), "{}", to_string(MI));
      }
    };
    Matthias Moulin
    @matt77hias
    Hey, if one just wants to print a string (which can potentially contain formatting related character sequences), should one use fmt::print("{}", str); or fmt::print(str);. For example: Print("({:.1f}, {:.1f})"); works, but it could be a hack as this is not explicitly documented. Furthermore, if both are valid, which one is the most performant and thus recommended?
    Victor Zverovich
    @vitaut
    @matt77hias use fmt::print("{}", str) as with printf and Python's str.format.
    fmt::print("({:.1f}, {:.1f})") won't work: https://godbolt.org/z/YqpUyh
    @peperunas sorry missed your message. You probably figured it out already, but you should put typename FormatContext::iterator there.
    Matthias Moulin
    @matt77hias
    @vitaut Thanks! (Just realized that Print("({:.1f}, {:.1f})"); is my own wrapper handling the no arguments case in a separate overload, my bad.)
    Widualk
    @Widualk
    can someone help me to implement fmt library in visual studio 2019?
    Roman
    @rdxroman
    @vitaut Hi. Could you please elaborate whether std::format will support compile time validation (similar to FMT_STRING)?
    Victor Zverovich
    @vitaut
    Not in C++20.
    Claudiu Andries
    @WiDuAlK12
    what configuration i need to make for build?
    Victor Zverovich
    @vitaut
    Aaron Bishop
    @Erroneous1
    I'd like to explicitly enable narrow to/from wide string conversion for my project using fmt. I added a custom fmt::formatter<std::wstring_view, char> and fmt::formatter<std::string_view, wchar_t>, and more formatters to handle std::wstring, std::string, const wchar_t*, and const char*. But I'm getting a static assertion failure "mixing character types is disallowed". Is there any way to do this besides converting the original string before formatting or the resulting string after formatting?
    Victor Zverovich
    @vitaut
    You'll need to write your own formatting function that applies conversion to string arguments before forwarding them to fmt::format.
    Aaron Bishop
    @Erroneous1
    Thanks. A little more verbose than I'd like but definitely doable.
    arkantos493
    @arkantos493
    https://godbolt.org/z/r9_YuH
    Is it possible to get this code working (without that exception) WITHOUT the need to change the func_sig string (which comes from the __PRETTY_FUNCTION__ macro).
    Victor Zverovich
    @vitaut
    Yes, all you need is to pass the resulting string as an argument instead of the format string: https://godbolt.org/z/hr7Ayt
    i.e. fmt::print(stderr, "{}", to_string(buf));
    arkantos493
    @arkantos493
    Thank you very much for your help. Now it works as intended.
    Andreas K
    @vulptex
    good morning
    Daniel Guzman
    @roig
    Hello, Is it possible to print only the first 4 numbers of an integer?
    Victor Zverovich
    @vitaut
    fmt::format("{}", n).substr(0, 4)
    jbeach
    @jasonbeach

    I've been using fmt while (as part of spdlog) for a while and think it's absolutely fantastic (like seriously--while concepts and coroutines are great and all, I think fmt getting into c++20 is just as big of a deal).

    One mistake that seems to keep biting us is format string errors of the form:
    fmt::format("missing format: ", number) i.e. the number of {} in the format string doesn't match the number of supplied arguments. I was surprised the first time I saw this that statements like this compile fine without warning. Is there a way to get errors like this to throw a compile time error?

    Victor Zverovich
    @vitaut
    No, extra arguments are intentionally accepted. It might be possible to write a lint to warn about them.
    jbeach
    @jasonbeach
    Interesting... Out if curiosity, what's the use-case for allowing extra arguments?
    Victor Zverovich
    @vitaut
    Conceptually they are the same as unused arguments in a function. IIRC there were use cases where you could conditionally use some of the arguments.