|
Boost : |
Subject: [boost] [offtopic] Wonders of C++ syntax
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2014-03-05 14:31:55
Maybe this experience will be interesting to someone...
I'm currently trying to write a simple parser for function signatures
for Boost.Log and collecting different curious use cases. The parser
is supposed to extract the function name from the compiler-generated
string with the signature (i.e. BOOST_CURRENT_FUNCTION).
Now the interesting case I've stumbled upon is a conversion operator
to a function pointer:
namespace namespc {
struct my_class2
{
typedef char (*pfunc_t)(double);
operator pfunc_t () const
{
std::cout << BOOST_CURRENT_FUNCTION << std::endl;
return 0;
}
};
}
I first tried to imagine how this could be written without the
typedef, but my brain broke soon enough. Then I decided to ask the
compiler, and naturally different compilers gave different answers.
GCC nicely sidestepped the problem altogether:
namespc::my_class2::operator pfunc_t() const
MSVC was more creative:
__cdecl namespc::my_class2::operator char (__cdecl
*)(double)(__cdecl *(void) const)(double)
Frankly, my brain can't parse this one either and it looks incorrect
to me since the function pointer type is duplicated.
So it seems, there's no syntax for expressing the operator without a
typedef, is that right? In that case, I wonder what to do with MSVC
output...
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk