Post by Nicol BolasPost by Magnus FromreideI think that one primary motivation for a fmt type interface is to ease
internationalization efforts. From there follows that one common output
target would be a streambuf. Now, I know that streams and performance in
the
Post by Magnus Fromreidesame sentence is dodgy at best but why make it even worse with an
unneeded
streambuf is fine, I guess. We need one output, not a template/concept.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
I don't know for sure, but if it took bets I suspect a template/concept is
exactly what you want here.
Or at least one of the options.
I don't know what the template/concept would be, but at a minimum it would
be a buffer template/concept.
I think we need this anyway. At a maximum maybe something like formatable
or something is needed
that employed the former somehow. But I've no idea and I haven't looked at
what cpp format does hardly.
But it seems to have such words there and I'm sure it has the feature set
covered.
The issue to me is how much nicer/simpler it can be if it's in the standard
and the standard can change to accommodate making it nicer.
If the end result looked anything less than easy to use or fast for string
then I wouldn't object
to string having a special case that addressed this.
But I seems remiss if don't support these use cases:
extern "C" bool get_logfilename(char* buffer, int buffer_length)
{
fixed_buffer fb(buffer, buffer_length), whatever);
auto status = cpp::format(fb, whatever);
return !status.failed();
}
std::pair<bool, std::size_t> get_logfilename(char* buffer, int
buffer_length)
{
fixed_buffer fb(buffer, buffer_length), whatever);
auto format_status = cpp::format(fb, whatever);
if (format_status.failed())
return {false,{}};
return {true, buffer, format_satus.format_length);
}
std::pair<bool, std::size_t> get_logfilename(char* buffer, int
buffer_length)
{
auto fb { std::make_fixed_buffer(buffer,, buffer_length) };
auto format_status = cpp::format(fb, whatever);
if (format_status.failed())
return {false,{}};
return {true, buffer, format_satus.format_length);
}
std::string get_logfilename()
{
std::string logfilename
strng_buffer sb(logfilename);
auto format_status = cpp::format(sb, whatever);
return logfilename;
}
So we have these adaptors that adapt types as needed, .e.g. string_buffer
etc.
They model a buffer concept that would seem to require this:
is_fixed_size()
size()
resize()
resize_default_init(); // The boost/nicol proposal
capacity()
The fixed_buffer type provides an interface that models buffer
but allow writing into an arbitrary fixed size memory region.
A buffer that can't resize has is_fixed_size return true.
And then the other adaptors like string_buffer as needed but:
I don't see why std::unique_ptr can't also be invited to the party here.
But if not, oh well.
But I see no reason why std::string, std::vector, std::array can't model a
buffer directly but they don't have to.
If they did, wouldn't you be down to:
std::string get_logfilename()
{
std::string logfilename
auto format_status = cpp::format(logfilename, whatever);
return logfilename;
}
I don't want anyone to get hung up on this particular interface. The main
things
to me (in order of importance) is what the interface support these goals,
* we don't require memory allocation to format. (essential)
* we support types beyond string unless there is a good reason not to.
* we can format and avoid exceptions if we wish
* we can diagnose when something failed and why so we can then throw if
it's important.
* we enable init/default initialized resize to be used here to help
efficiency. it seems formatting can use this.
We need to know how certain formatting conditions fail and not just have
only a failed bit to check.
IMO we need to know at least:
out of memory (malloc/new failure),
buffer full (i.e. wanted to resize() but is_fixed_size() said no),
bad format string,
bad argument
I think we need to maximally attempt to format as much as possible and not
throw.
but format_status can contain an std::expected or something that exactly
says the issue.
you can expect that but typically wouldn't.
But lets see evidence supports these positions.
All of this seems achievable and cpp format seems to provide a lot of this
feature set.
To me it's just seeing if cpp format does support this needs and how and
why not and then
seeing how the Standard needs to change to make formatting even
easier/simpler than
whatever cpp format already does without that support today.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/0136a5fe-14a0-41d8-ae27-330cd513fde8%40isocpp.org.