It looks like that c++20 std::format is not a direct replacement for the fmt library.
Looking at the API (https://en.cppreference.com/w/cpp/utility/format) it looks like that fmt::dynamic_format_arg_store is not part of the standard.
Currently in fmt you can have the following code:
#include <fmt/format.h>
#include <fmt/args.h>
int main()
{
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
store.push_back(42);
store.push_back( std::string { "abc1"} );
store.push_back(1.5f);
fmt::vprint("{} this is my {}. This is a number: {}.", store);
}
I would like to replace fmt with the standard std::format.
I had a very quick look at fmt::dynamic_format_arg_store and it looks like it is using a few internal things from fmt so it didn't look that straight forward.
Anyone can provide some guidance on how to implement the above functionality outside of fmt for C++20 using std::format ?
edit:
Looking a bit deeper in fmt:dynamic_format_arg_store it looks like it is using detail:make_arg to create an argument.
I don't know how I can get something equivalent from std::format as I only see std::make_format_args which returns a different type.
Is fmt:dynamic_format_arg_store possible to be implemented for std:format without getting into implementation specific details for each compiler ?
You cannot portably implement an equivalent of fmt::dynamic_format_arg_store for std::format yourself because the representation of std::basic_format_args is an implementation detail of the standard library. It might be provided in one of the future versions of the C++ standard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With