ETLCPP / etl

Embedded Template Library
https://www.etlcpp.com
MIT License
2.25k stars 392 forks source link

CAPACITY in `basic_string` could be constexpr on the platforms that are supported #970

Closed brawner closed 2 weeks ago

brawner commented 1 month ago

Currently CAPACITY in the basic_string class is listed as const size_type CAPACITY. For platforms that support constexpr, it wouldn't need to be part of its memory footprint if it were constexpr.

brawner commented 1 month ago

I was also wondering then if max_size() could be a static function?

jwellbelove commented 1 month ago

CAPACITY cannot be constexpr as its value is passed to the base classes ibasic_string and string_base. These two classes are 'size agnostic' in that they are common code shared between all sizes of string, in string_base's case, all sizes and character types. This is also the reason why max_size() and capacity() cannot be static.

etl::basic_string<char, 10> -> etl::ibasic_string<char> -> string_base

The top level, size dependent, string classes expose a static constant MAX_SIZE.

I could maybe add constexpr max_size() and capacity() overloads to the top level classes?

brawner commented 1 month ago

Thanks for the response, I see that such a change would not be possible without breaking changes.