Sorry for top posting here, but I didn't receive Steven's response.
I'm using i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build
5488).
The compile error I get is the following:
g++ -I/Users/jpritts/trunk/LIFEBLAST_HOME/i386-darwin-gcc-4_0/vendor/Boost/include
main.cc -o a.out
main.cc: In instantiation of 'DoesVisitorImplement
On a boost thread a while ago, I saw some code to query for the existence of a member function of a class using SFINAE and BOOST_STATIC. I guess you could call it static reflection. Below is a code snippet that does not work using the aforementioned methods. The culprit is the using Base::operator() statement in the Derived class. Apparently the base class method void operator()(float u) is not part of the type of Derived. This was a shock to me, because you can call the overloaded method from the derived class. I'd appreciate any advice on how to check for the existence of member functions in this scenario. I fear it may be impossible. Thanks!
You can convert a member function pointer of a derived class to a member function pointer of a derived class, so it ought to work. What compiler are you using? I get 1 1 Using msvc 9.0. In Christ, Steven Watanabe
Hi,
Sorry for top posting here, but I didn't receive Steven's response. I'm using i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5488).
I used to do some member function pointer tests myself, and I was stopped by c++/8171 (fixed in gcc 4.3.0). See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8171 I don't know if it is the case here though. Cheers, Filip
On Thu, 18 Sep 2008 10:15:23 +0200
Filip Konvička
Hi,
Sorry for top posting here, but I didn't receive Steven's response. I'm using i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5488).
I used to do some member function pointer tests myself, and I was stopped by c++/8171 (fixed in gcc 4.3.0).
See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8171
I don't know if it is the case here though.
Nope - tried on Linux i686, GCC 4.3.0 and the same error as reported by James. -- Manfred 18 September, 2008
So is the error valid, meaning does the error conform the C++
standard? In that case MSVC 9 would be the compiler in error, and
the code is malformed. There is a subtlety to the using keyword when
making base class overloaded member visible. I read that using
"introduces" the member function to the scope of the derived class,
rather than making it part of the derived class's type. The gcc
compiler is refusing to cast the
ReturnType(DerivedClass::*)(ArgumentType) to
ReturnType(BaseClass::*)(ArgumentType). This is a show stopper
because there is no way to explicitly get the address of the
overloaded base class member. e.g. I cannot say
&Class::operator(float), I can only say &Class::operator() and the
lvalue in an assignemtn statement determines which function address to
acquire. In a larg inheritance tree, however, I would have no way of
knowing what base class the overloaded operator is defined in.
I was using MPL to automatically create boost::variant static visitors
from a group of standalone classes by using inheritance. The using
keyword is required because visitors overload operator()(...) for
their various types, and overloaded members are hidden by default when
inheriting. I never understood why this is the case.
Later in the code, I need to check if the static visitor supports a
type at run time. This is why I need member function introspection,
and it would have worked save for this one obscure snafu. It works on
MSCV9 according to Steven, but that does me no good.
Jimmy.
On Thu, Sep 18, 2008 at 5:12 AM, Manfred Doudar
On Thu, 18 Sep 2008 10:15:23 +0200 Filip Konvička
wrote: Hi,
Sorry for top posting here, but I didn't receive Steven's response. I'm using i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5488).
I used to do some member function pointer tests myself, and I was stopped by c++/8171 (fixed in gcc 4.3.0).
See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8171
I don't know if it is the case here though.
Nope - tried on Linux i686, GCC 4.3.0 and the same error as reported by James.
-- Manfred 18 September, 2008 _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
AMDG James Pritts wrote:
So is the error valid, meaning does the error conform the C++ standard?
Apparently, it is. "For a non-type template-parameter of type pointer to member function, no conversions apply" (13.3.2/5)
<snip>
Later in the code, I need to check if the static visitor supports a type at run time. This is why I need member function introspection, and it would have worked save for this one obscure snafu. It works on MSCV9 according to Steven, but that does me no good.
I think that you can use overload resolution instead of SFINAE (untested).
struct fallback { fallback operator,(int); };
yes is_fallback(fallback);
no is_fallback(...);
template<class C>
struct has_function_call_operator_impl : C {
using C::operator();
fallback operator()(...) const;
};
template<class T>
T make();
template ()(make<Arg>()))) == sizeof(no) };
}; In Christ,
Steven Watanabe
participants (4)
-
Filip Konvička
-
James Pritts
-
Manfred Doudar
-
Steven Watanabe