For example i'm making a library which provides function void foo( std::string color )
And i need to somehow tell the user of my library that function foo
supports only certain values for argument color
(for example only "red", "green" or "blue").
Usually i make something like this
namespace ColorValues
{
enum values
{
RED,
GREEN,
BLUE
}
std::string toString( ColorValues::values value )
{
switch( value )
{
case RED: return "red";
case GREEN: return "green";
case BLUE: return "blue";
default: return "error";
}
}
}
void foo( ColorValues::values value )
{
std::string theStringINeed = ColorValues::toString( value );
}
But thats just ... too cumbersome, but i dont know any other way and cpp doesn't support string enums.
What to do?