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

use fmt::format_to with vector<char> and FMT_COMPILE #4206

Closed
trim21 opened this issue Oct 20, 2024 · 3 comments
Closed

use fmt::format_to with vector<char> and FMT_COMPILE #4206

trim21 opened this issue Oct 20, 2024 · 3 comments

Comments

@trim21
Copy link
Contributor

trim21 commented Oct 20, 2024

I'm new to c++, apology if this is not a good issue.

I'm coming from #1771 , but I'm using a vector<char> as memory buffer.

And fmt::format_to(std::back_inserter(out), FMT_COMPILE("{}"), val) works if out is std::string of fmt::memory_buffer but not std::vector<char>, and fmt::format_to(std::back_inserter(buffer), "{}", val) works for vector<char>

Is it possible to add support for vector<char> and FMT_COMPILE?

https://godbolt.org/z/h6xoG65he

@trim21 trim21 changed the title fmt::format_to with vector<char> and FMT_COMPILE can't work together. use fmt::format_to with vector<char> and FMT_COMPILE Oct 20, 2024
@vitaut
Copy link
Contributor

vitaut commented Oct 20, 2024

Thanks for reporting. We should detect presence of append with SFINAE in

fmt/include/fmt/base.h

Lines 1974 to 1981 in 2b6a786

// An optimized version of std::copy with the output value type (T).
template <typename T, typename InputIt, typename OutputIt,
FMT_ENABLE_IF(is_back_insert_iterator<OutputIt>::value)>
FMT_CONSTEXPR20 auto copy(InputIt begin, InputIt end, OutputIt out)
-> OutputIt {
get_container(out).append(begin, end);
return out;
}

@vitaut
Copy link
Contributor

vitaut commented Oct 26, 2024

Done in #4211.

@vitaut vitaut closed this as completed Oct 26, 2024
@trim21
Copy link
Contributor Author

trim21 commented Oct 26, 2024

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants