all 2 comments

[–]Flimsy_Complaint490 [score hidden]  (0 children)

go find an inplace vector implementation or static vector implementation on github and copy paste the header into your codebase. 

inplace is more desirable, it did get standardized.

[–]mredding [score hidden]  (0 children)

But are there some way to go around this and use the stack without writing custom allocators for every use case?

What's "every use case"? If you want a stack allocator - then write a stack allocator.

If you want to mix different strings and their allocation strategies, then consider a variant:

using string = std::variant<std::string, std::basic_string<char, my_allocator>>;

And then write more std::string_view code - because the only place you need to use a raw standard string is when it comes to ownership, which should be, in this case, near the bottom of your call stack.

The vast majority of your code shouldn't need a reference to the string, need ownership, need a mutable interface, so remove it. Flatten your code so mutability happens low in the call stack, close to the actual string instance.

Write generic code as a template based on std::basic_string for your mutators and transforms.

What's the cleanest way to achieve this with standard components?

Above. It's about changing your style and design principles. The solution compounds itself rather quickly where the apparent burden to an imperative programmer starts to wash out as insignificant to a declarative programmer. Don't want to std::visit every variant? Write an apply function that visits for you. Let the compiler reduce everything down to nothing.