This problems seems like a very common issue, yet I am unable to find a solution for it. And I'm almost convinced that functionality like this should be a part of boost or other popular library.
I want to have a drop-in replacement for a std::string for which I could specify minimal and maximal length, preferably at compile time. Optionally, it could also support state with no string set (in a boost::optional
way). Something like this:
ranged_string<min, max> str;
When assigning invalid value, an exception should be thrown.
Creating such utility myself shouldn't be very hard (just some overloads and exception throws), but I don't want to reinvent the wheel.