I am trying to create an exception class. For this I overloaded the <<
operator. So the code is something like this
class RunAndCheck
{
opearator << (boost::any given)
{
//Here goes the value of the "given"
}
};
The usage is like this
RunAndCheck s;
s << file->open() << __FILE__ << __LINE__ ;
So the problem is that I want to know the type of the FILE, then only I can extract the string out of boost::any
. Can anybody invoke your curiosity around this?
__FILE__ expands into a string literal, just as if you had written "/path/to/current/file.cpp" directly. String literals are non-modifiable char array lvalues.
You want to template that << instead of using boost::any:
class RunAndCheck {
public:
template<class T>
RunAndCheck& operator<<(const T& value) {
// ...
return *this;
}
};
Or you want to provide overloads for all the acceptable types:
class RunAndCheck {
public:
RunAndCheck& operator<<(const char* value) {
// ...
return *this;
}
RunAndCheck& operator<<(int value) {
// ...
return *this;
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With