Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++what is the type of the __FILE__ macro

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?

like image 310
prabhakaran Avatar asked Feb 21 '11 10:02

prabhakaran


1 Answers

__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;
    }
};
like image 171
Thomas Edleson Avatar answered Oct 23 '22 07:10

Thomas Edleson