The most reasonable interpretation to me is that you're asking how to
set the initial /capacity/ of the vector in the declaration, to avoid an
explicit .reserve() invocation as a separate following statement.
Presumably because you declare such vectors in many places.
To do that you can to wrap the vector, either via a factory function or
via a simple class, like
struct Capacity{ int value; };
struct Fast_stringvec:
public vector<string>
{
template< class... Args >
Fast_stringvec( const Capacity capacity, Args&&... args ):
vector<string>( forward<Args>( args )... )
{
reserve( capacity.value );
}
};
Then do e.g.
auto formulas = Fast_stringvec( Capacity( max_ncp ) );
... where I believe the use of `auto` helps avoid the Most Vexing Parse. ;-)
If `max_ncp` is a constant you can add a constructor that uses that by
default.
---
A not so reasonable interpretation is that you're asking how to make the
vector contain `max_ncp` strings initially, for which you can just do
vector<string> formulas( max_ncp, ""s );
---
Crossing the line to perhaps unreasonable interpretation is that you're
asking how you can make it so that when you add a new to string to the
vector, the new string item will guaranteed be of size `max_ncp`.
For that you need to make the item type one that holds a `string` of
exactly that size.
It would probably be necessary to take control of copying to such items,
to avoid inadvertent size changes.
- Alf