I have in mind a construct like this:
template <typename T, T defaultValue>
struct Numeric
{
Numeric(T t=defaultValue) : value(t) { }
T value;
T operator=()(T t);
operator T();
};
I might use it like this:
std::vector<Numeric<bool, true> > nothingButTheTruth;
My question is simple: Is this a good approach and if so, does something like this exist in a standard library or Boost?
The pattern I see more commonly is to parameterize the container, not the type.
There are a lot of downsides to doing it your way:
a
bool&to aNumeric<bool, true>.vector<bool>and avector<Numeric<bool, true> >are unrelatedtypes.
This gets pretty painful pretty quickly. I wouldn’t do it, but perhaps you have a strong use case.