variable a = "Hello";
variable b = 'a';
variable c = 34;
/* ... */
a = 34;
b = "Hello";
c = 'a';
.. everything is going smoothly. however, I am looking for some opinions on overloaded operator behaviors. I was thinking maybe subtracting two 'string' types of variable could perform STL's remove() or some other useful thing... example:
1 2 3
variable c = "Hello Everyone";
variable m = "e";
variable New = c-m; // "Hllo Evryon"
or anything along those lines..
note the variable class is not a template class, only its constructor:
boost::any a = 5;
a = 3.14;
a = std::vector<int>( 4 );
a = "Hello world";
works just fine.
The trick is that in order to get the value back out of the boost::any, you have to know the type it is holding.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
boost::any a = 3.14;
try {
int x = boost::any_cast<int>( a );
std::cout << "a is integral, and holds value " << x << std::endl;
} catch( const boost::bad_any_cast& ) {
std::cout << "a does not hold an integer!";
}
try {
double d = boost::any_cast<int>( a );
std::cout << "a is floating point (double), and holds value " << d << std::endl;
} catch( const boost::bad_any_cast& ) {
std::cout << "a does not hold a double!";
}
would print*
a does not hold an integer!
a is floating point (double), and holds value 3.14
*For illustration only; actual value output may vary (scientific notation, etc).