Can anyone guide me on how to solve this problem. I have a boost::variant.
typedef boost::variant <
int,
std::string,
bool,
double,
vector<int>,
vector<string>,
vector<bool>,
vector<double>
> boostVar;
I am trying to create overload []
operator as member function of a class ABC
something like this (this is just a dummy implementation)
class ABC
{
//some map of (key, value) pair that where key is string and value is of type boostVar
boostVar [](const string key)
{
boostVar temp;
//some operation that fills up temp based on value of key
return temp;
}
}
So while retrieving the a particular value using this implementation, it forces user to specify
int key1Val = boost::get<int>(ABC["KEY1"]);
bool key2Val = boost::get<bool>(ABC["KEY2"]);
vector<int> key3Val = boost::get<vector<int>>(ABC["KEY3"]);
my question is:
How should I go about implementing this if I want to access the values like below (i.e. without boost::get<>)
int key1Val = ABC["KEY1"];
bool key2Val = ABC["KEY2"];
vector<int> key3Val = ABC["KEY3"];
The implementation should give warning to user if the say: KEY1 does not match int, KEY2 does not match bool and so on.