Skip to content

Use contiguous_range when available#4716

Open
user202729 wants to merge 1 commit intofmtlib:masterfrom
user202729:use-contiguous-range
Open

Use contiguous_range when available#4716
user202729 wants to merge 1 commit intofmtlib:masterfrom
user202729:use-contiguous-range

Conversation

@user202729
Copy link
Contributor

@user202729 user202729 commented Mar 15, 2026

This provides further 20% speedup for vector<char> when used on top of #4679 (with the linked benchmark that has since then been rejected, but for the purpose of measuring the code runtime, it works well enough), for understandable reasons.

If one wants support for faster format to vector<char> before C++20, it's possible to specialize is_contiguous for vector, array etc. But I don't think it's worth it. For example, such template specialization would not work with custom string types.

I don't know if <ranges> is too heavy for base.h. There is contiguous_iterator instead in <iterator>. https://en.cppreference.com/w/cpp/iterator/contiguous_iterator.html


Side note, thinking about it, since base.h defines is_contiguous to be always false, but format.h defines it to be true for string, wouldn't this lead to potential ODR?

  • compilation unit A includes only base.h and use (something that uses) is_contiguous<string>.
  • compilation unit B includes format.h and use (something that uses) is_contiguous<string>.

In practice, it's probably fine though.

@user202729 user202729 force-pushed the use-contiguous-range branch 2 times, most recently from 713d88f to e668131 Compare March 15, 2026 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant