What about simply using the const/invariant information?
After all, an "array builder" is a mutable array. If you don't want to extend it, it should be invariant or const - e.g. invariant(string).
I've always thought the separation of strings and string builders, arrays and array builders, etc. was flawed. It's just like strcmp; sure, it works, but is it really the right way to compare strings? Can't I just have my == and not worry about it?
-[Unknown] Robert Jacques wrote:
3) Over-allocating all arrays is a wonderful waste of memory and performance (re chache lines, etc). A cleaner answer is an array builder class, which only pays for this overhead when it's actually needed.