
Hello all, Is there a way I can check if a class has a given member function using metaprogramming? What I need is to check at compile-time if a function is overriding a virtual function or not. In the example below, z::f is overriding x::f but not y::f (which does not exist) and the compiler knows that -- is there a way I can extract that information from the compiler? struct has_function<class Base, ... /* other parameters */ > { ... /* some implementation */ }; struct x { virtual void f() {} }; struct y { virtual void g() {} }; struct z: x, y { void f() { cout << has_function<x, &z::f>::value << endl; // print 1 cout << has_function<y, &z::f>::value << endl; // print 0 } }; (This does not compile -- I do not know how to program it so it compiles -- but it should give the idea of what I am looking for.) Thank you very much. Lorenzo

Lorenzo Caminiti wrote:
Hello all,
Is there a way I can check if a class has a given member function using metaprogramming?
What I need is to check at compile-time if a function is overriding a virtual function or not. In the example below, z::f is overriding x::f but not y::f (which does not exist) and the compiler knows that -- is there a way I can extract that information from the compiler?
Well, there is an introspection library in the vault but I think I didn't took this case into account. Worth a try tough -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35

Hi, ----- Original Message ----- From: "Lorenzo Caminiti" <lorcaminiti@gmail.com> To: <boost@lists.boost.org> Sent: Sunday, March 21, 2010 2:11 PM Subject: [boost] [mpl] has_function
Hello all,
Is there a way I can check if a class has a given member function using metaprogramming?
What I need is to check at compile-time if a function is overriding a virtual function or not. In the example below, z::f is overriding x::f but not y::f (which does not exist) and the compiler knows that -- is there a way I can extract that information from the compiler?
struct has_function<class Base, ... /* other parameters */ > { ... /* some implementation */ };
struct x { virtual void f() {} };
struct y { virtual void g() {} };
struct z: x, y { void f() { cout << has_function<x, &z::f>::value << endl; // print 1 cout << has_function<y, &z::f>::value << endl; // print 0 } };
(This does not compile -- I do not know how to program it so it compiles -- but it should give the idea of what I am looking for.)
maybe you can take a look at https://svn.boost.org/trac/boost/wiki/LibrariesUnderConstruction#Boost.Conce... This library was abandoned because Concepts will be part of the language. It contains alot of traits about if a class ddefines a function. I don't know if there is some some traits for virtual functions. Let us know, Vicente

Lorenzo Caminiti wrote:
Is there a way I can check if a class has a given member function using metaprogramming?
Yes.
What I need is to check at compile-time if a function is overriding a virtual function or not.
This is not the same, and there is no way to do that as far as I know.

The only thing you can determine, is, if the type (class) of the last declaration is the one you expected. That means if you know that the first declaration of your function comes in from baseT, you can determine if a deriving class overwrites that decl, and that is exactly what a deriving class needs to do to overload a virtual function. I myself use this pattern to determine, if a type is an XPCOM Interface or not. Perhaps you'd like to check for something similiar. If interested in details, let me know. Mathias Gaunard <mathias.gaunard@ens-lyon.org> Sent by: boost-bounces@lists.boost.org 21.03.2010 19:31 Please respond to boost@lists.boost.org To boost@lists.boost.org cc Subject Re: [boost] [mpl] has_function Lorenzo Caminiti wrote:
Is there a way I can check if a class has a given member function using metaprogramming?
Yes.
What I need is to check at compile-time if a function is overriding a virtual function or not.
This is not the same, and there is no way to do that as far as I know. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

On Sun, Mar 21, 2010 at 2:43 PM, Ingo Loehken <Ingo.Loehken@boc-eu.com> wrote:
The only thing you can determine, is, if the type (class) of the last declaration is the one you expected. That means if you know that the first declaration of your function comes in from baseT, you can determine if a deriving class overwrites that decl, and that is exactly what a deriving class needs to do to overload a virtual function.
I myself use this pattern to determine, if a type is an XPCOM Interface or not. Perhaps you'd like to check for something similiar.
If interested in details, let me know.
Yes, I am interested. Can you please point me to some code that programs this pattern? Thanks a lot. Lorenzo

The only thing you can determine, is, if the type (class) of the last declaration is the one you expected. That means if you know that the first declaration of your function comes in from baseT, you can determine if a deriving class overwrites
below you find the appropiate code, that checks if a set of functions is declared for a type T, where the declaration should be inherited from nsISupports (or any other interface). So you'd can determine, if the function is overloaded or not. This code is inspired by the following article http://groups.google.com/group/comp.lang.c++.moderated/tree/browse_frm/threa... /** Compile Time Predicate, which checks, if a type is a valid template * parameter for a COMPtr, where only interfaces are valid input parameters. * * The idea is simple : * An interface always inherits from nsISupports and does not overload the * pure virtual declarations of AddREf, Release and QueryInterface. Therefore * the addresses of that function pointers need to be bound to nsISupports. * * Of course, one issue remains unsolved : * What is with abstract classes, which inherit from nsISupports, but already * have their own implementation ? * Currently there is no way, to check, if a class is pure virtual, thus we * neglect that issue. * */ template <typename T> struct IsCOMInterface : public Supports_::BasicTestPredicate<IsCOMInterface<T> > { private: // we are only able to determine this predicate for complete types, a // forward declare (incomplete type) may be a COM interface, but would be // excluded as an error to its incompleteness. Therefore the only thing, // that is always correct is to assert in such conditions. BOOST_MPL_ASSERT_RELATION((sizeof(T)),>,0); static T* Make(); static false_t Test1(...); template <typename _1> static true_t Test1(_1*, equal<nsrefcnt (__stdcall nsISupports::*)(),&_1::AddRef>* = 0); static false_t Test2(...); template <typename _1> static true_t Test2(_1*, equal<nsrefcnt (__stdcall nsISupports::*)(),&_1::Release>* = 0); static false_t Test3(...); template <typename _1> static true_t Test3(_1*, equal<nsresult (__stdcall nsISupports::*)(nsID const&,void**),&_1::QueryInterface>* = 0); public: static const value_type value = sizeof(Test1(Make())) == sizeof (true_t) && sizeof(Test2(Make())) == sizeof(true_t) && sizeof(Test3(Make ())) == sizeof(true_t); }; namespace IsCOMInterface_ { BOOST_MPL_ASSERT((IsCOMInterface<nsISupports>)); BOOST_MPL_ASSERT((IsCOMInterface<nsIWeakReference>)); struct Test1 {}; BOOST_MPL_ASSERT_NOT((IsCOMInterface<Test1>)); struct Test2 { NS_IMETHOD_(nsrefcnt) AddRef(); NS_IMETHOD_(nsrefcnt) Release(); NS_IMETHOD QueryInterface(nsID const&, void**); }; BOOST_MPL_ASSERT_NOT((IsCOMInterface<Test2>)); struct Test3 : public nsISupports { NS_IMETHODIMP_(nsrefcnt) AddRef(); }; BOOST_MPL_ASSERT_NOT((IsCOMInterface<Test3>)); } namespace Supports_ { /** * */ template <typename derivedT> struct BasicTestPredicate { protected: typedef char true_t; struct false_t{true_t dummy[2];}; template <typename V, V> struct equal; public: typedef bool value_type; typedef derivedT type; }; } // namespace Supports_ Lorenzo Caminiti <lorcaminiti@gmail.com> Sent by: boost-bounces@lists.boost.org 22.03.2010 13:33 Please respond to boost@lists.boost.org To boost@lists.boost.org cc Subject Re: [boost] [mpl] has_function On Sun, Mar 21, 2010 at 2:43 PM, Ingo Loehken <Ingo.Loehken@boc-eu.com> wrote: that
decl, and that is exactly what a deriving class needs to do to overload a virtual function.
I myself use this pattern to determine, if a type is an XPCOM Interface or not. Perhaps you'd like to check for something similiar.
If interested in details, let me know.
Yes, I am interested. Can you please point me to some code that programs this pattern? Thanks a lot. Lorenzo _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Hi, I've discovered boost for myself for about a year ago. I treat this library as an addiction to STL, something to improve the speed and the quality of C++ development. Yesterday I'd found out that boost is participating in Google SoC. The ideas listed by the mentor are in fact very interesting and useful in many ways. But there are some of my own. I'd like to consult you if they are acceptable by the project. The first one I want to discuss is containers. Of course there are some in stl, but they provide to user no control of their internal structure and realization. For example there are situations, when I need a container to be thread-safe and there are one when I don't. There are situations when I want atomic pop in the queue. Or may be I want container to be thread-safe. Or I want deque to be realized not upon an array, but upon the map. There a lot of such modifiers and there is no way in stl or boost to handle this. So, my first idea is to create highly customizable containers with template parameters. But i'm afraid that I wasn't the first who'd like to do so and there are some restrictions in project philosophy. The second thing I want to suggest is the creation of neural net library. You can ask if there any serious reasons to do this in a common library. I think that elements of primitive AI would simplify realization of some heuristic methods and algorithms. And of course the boost users would highly appreciate this opportunity. I'm willing to hear your comments. Best wishes, Biin Ilya.

just to throw another couple of ideas what about such essential things like data compression and data encription? i think these two will perfectly fit into boost as policy driven (template?) libraries at least there would be a kind of standard interface to these facilities -- Pavel

On 22 March 2010 15:27, DE <satan66613@yandex.ru> wrote:
what about such essential things like data compression and data encription?
i think these two will perfectly fit into boost as policy driven (template?) libraries
at least there would be a kind of standard interface to these facilities
How about, as a prerequisite to a larger encryption library, more cryptographic hashes? For instance, UUID has an SHA-1, but would rather not maintain its own. Also, there are MD5-based UUIDs that the library can't provide yet, since it lacks an MD5 hasher. I suspect a boost asymmetrical encryption system will need to wait until we finally get a bigint library.

On Mar 22, 2010, at 12:51 PM, Scott McMurray wrote:
On 22 March 2010 15:27, DE <satan66613@yandex.ru> wrote:
what about such essential things like data compression and data encription?
i think these two will perfectly fit into boost as policy driven (template?) libraries
at least there would be a kind of standard interface to these facilities
How about, as a prerequisite to a larger encryption library, more cryptographic hashes?
For instance, UUID has an SHA-1, but would rather not maintain its own. Also, there are MD5-based UUIDs that the library can't provide yet, since it lacks an MD5 hasher.
Except for the scope (I think this might be a big small), I think this would make a good SOC project. MD5, SHA-1, SHA-2, with a place for the current NIST contest winner when it is decided. If there is time, the concepts can be used to implement some symmetrical encryption algorithms (RC4, RC5, AES, etc). -- Marshall

How about, as a prerequisite to a larger encryption library, more cryptographic hashes?
For instance, UUID has an SHA-1, but would rather not maintain its own. Also, there are MD5-based UUIDs that the library can't provide yet, since it lacks an MD5 hasher.
Except for the scope (I think this might be a big small), I think this would make a good SOC project. MD5, SHA-1, SHA-2, with a place for the current NIST contest winner when it is decided.
If there is time, the concepts can be used to implement some symmetrical encryption algorithms (RC4, RC5, AES, etc).
I think that's a very good idea. It might be worth pointing out that there is a boost.crypto submission in the vault [1] that seems to implement some of these algorithms. We should take a closer look at this library before suggesting a GSoC project. I'm pretty confident that this could (should?) be a good Boost library. Andrew Sutton andrew.n.sutton@gmail.com [1] http://www.boostpro.com/vault/index.php?action=downloadfile&filename=boost_crypto.zip&directory=&

I'll summarize extra ideas. So, it will be a container library with this list of features supported with template parametres: 1 - Mutithreading 2 - Exception safety 3 - Different internal realizations Also it will contain support of transformation algorithms, such as archiving, cryptography and others. After the first sight I'd like to offer realiation of that kind. We provide a special class which will implement stream operations being able to work with stl streams. There will be a template argument specifing an exact transform algorithm. It will extend the queue container to take use of it adjustability. Also it will give us an appotunity co create transformation chains. -- Biin Ilya MIPT

Also it will contain support of transformation algorithms, such as archiving, cryptography and others. After the first sight I'd like to offer realiation of that kind. We provide a special class which will implement stream operations being able to work with stl streams. There will be a template argument specifing an exact transform algorithm. It will extend the queue container to take use of it adjustability. Also it will give us an appotunity co create transformation chains.
Hi Biin, This sounds like a very ambitious project, and I'm not convinced that there is a huge demand for such a library in the Boost community. Also, building new Boost libraries may be a commitment of several years. Maybe you can revise your ideas to address the needs of Boost existing or upcoming Boost libraries? Andrew Sutton andrew.n.sutton@gmail.com

Hi Biin,
This sounds like a very ambitious project, and I'm not convinced that there is a huge demand for such a library in the Boost community. Also, building new Boost libraries may be a commitment of several years. Maybe you can revise your ideas to address the needs of Boost existing or upcoming Boost libraries?
Andrew Sutton andrew.n.sutton@gmail.com _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
There is a boost-crypto library in the vault, I think it will be possible and logical to implement this idea
Also it will contain support of transformation algorithms, such as archiving, cryptography and others. After the first sight I'd like to offer realiation of that kind. We provide a special class which will implement stream operations being able to work with stl streams. There will be a template argument specifing an exact transform algorithm. It will extend the queue container to take use of it adjustability. Also it will give us an appotunity co create transformation chains.
on top of it. Though there is a lot of algorithms there it's not ready for usage. -- Ilya Biin MIPT

On Mon, Mar 22, 2010 at 9:12 AM, Ingo Loehken <Ingo.Loehken@boc-eu.com> wrote:
below you find the appropiate code, that checks if a set of functions is declared for a type T, where the declaration should be inherited from nsISupports (or any other interface). So you'd can determine, if the function is overloaded or not.
It turned out that I only needed to check if a struct is declared within one of the base classes or not. This seems simpler that my original goal for has_function and I was able to adapt Ingo's code to get the job done -- see below. However, I am getting the following compiler error: $ g++ -Wall -Werror test/noinherit/05.cpp test/noinherit/05.cpp: In instantiation of ‘const bool z::has_contract_f_<x>::value’: test/noinherit/05.cpp:34: instantiated from here test/noinherit/05.cpp:31: error: the default argument for parameter 1 of ‘static char z::has_contract_f_<T>::check(C*, typename C::contract_f_<0>*) [with C = x, T = x]’ has not yet been parsed Do you know how I can get around this error? // File test/noinherit/05.cpp #include <iostream> struct x { virtual void f() {} template<int Z> struct contract_f_ {}; }; struct y { void g() {} template<int Z> struct contract_g_ {}; }; struct z: x, y { void f() {} template<int Z> struct contract_f_ {}; template<typename T> struct has_contract_f_ { private: typedef char true_t; struct false_t { true_t dummy[2]; }; static T* make(); static false_t check(...); template<typename C> static true_t check(C*, typename C::template contract_f_<0>* = 0); public: static const bool value = sizeof(check(make())) == sizeof(true_t); // line 31 }; static const bool bx = has_contract_f_<x>::value; // line 34 static const bool by = has_contract_f_<y>::value; }; int main() { std::cout << z::bx << std::endl; std::cout << z::by << std::endl; return 0; } If has_contract_f_ is declared outside struct z than there is no error -- the code compiles and works. However, I need has_contract_f_ to be a member struct of z, because of the way I use it within my library, and that generates the compiler error reported above. Thanks a lot. Lorenzo

Lorenzo Caminiti wrote:
It turned out that I only needed to check if a struct is declared within one of the base classes or not. This seems simpler that my original goal for has_function and I was able to adapt Ingo's code to get the job done -- see below. However, I am getting the following compiler error:
$ g++ -Wall -Werror test/noinherit/05.cpp test/noinherit/05.cpp: In instantiation of ‘const bool z::has_contract_f_<x>::value’: test/noinherit/05.cpp:34: instantiated from here test/noinherit/05.cpp:31: error: the default argument for parameter 1 of ‘static char z::has_contract_f_<T>::check(C*, typename C::contract_f_<0>*) [with C = x, T = x]’ has not yet been parsed
Do you know how I can get around this error?
// File test/noinherit/05.cpp
#include <iostream>
struct x { virtual void f() {} template<int Z> struct contract_f_ {}; };
struct y { void g() {} template<int Z> struct contract_g_ {}; };
struct z: x, y { void f() {} template<int Z> struct contract_f_ {};
template<typename T> struct has_contract_f_ { private: typedef char true_t; struct false_t { true_t dummy[2]; }; static T* make();
static false_t check(...); template<typename C> static true_t check(C*, typename C::template contract_f_<0>* = 0); public: static const bool value = sizeof(check(make())) == sizeof(true_t); // line 31 };
static const bool bx = has_contract_f_<x>::value; // line 34 static const bool by = has_contract_f_<y>::value; };
int main() { std::cout << z::bx << std::endl; std::cout << z::by << std::endl; return 0; }
If has_contract_f_ is declared outside struct z than there is no error -- the code compiles and works. However, I need has_contract_f_ to be a member struct of z, because of the way I use it within my library, and that generates the compiler error reported above.
Thanks a lot. Lorenzo
Compiles fine for me (MSVC9, Vista). - Jeff

AMDG Lorenzo Caminiti wrote:
It turned out that I only needed to check if a struct is declared within one of the base classes or not. This seems simpler that my original goal for has_function and I was able to adapt Ingo's code to get the job done -- see below. However, I am getting the following compiler error:
$ g++ -Wall -Werror test/noinherit/05.cpp test/noinherit/05.cpp: In instantiation of ‘const bool z::has_contract_f_<x>::value’: test/noinherit/05.cpp:34: instantiated from here test/noinherit/05.cpp:31: error: the default argument for parameter 1 of ‘static char z::has_contract_f_<T>::check(C*, typename C::contract_f_<0>*) [with C = x, T = x]’ has not yet been parsed
Do you know how I can get around this error? <snip> template<typename T> struct has_contract_f_ { private: typedef char true_t; struct false_t { true_t dummy[2]; }; static T* make();
static false_t check(...); template<typename C> static true_t check(C*, typename C::template contract_f_<0>* = 0); public: static const bool value = sizeof(check(make())) == sizeof(true_t); // line 31 };
<snip>
Does it work if you pass 0 explicitly instead of using a default argument. In Christ, Steven Watanabe

On Sat, Mar 27, 2010 at 11:56 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
<snip> template<typename T> struct has_contract_f_ { private: typedef char true_t; struct false_t { true_t dummy[2]; }; static T* make();
static false_t check(...); template<typename C> static true_t check(C*, typename C::template contract_f_<0>* = 0); public: static const bool value = sizeof(check(make())) == sizeof(true_t); // line 31 };
<snip>
Does it work if you pass 0 explicitly instead of using a default argument.
Unfortunately, it does not work (that is the first thing I tried...). If I change the `value` evaluation to: sizeof(check(make(), 0)) == sizeof(true_t); // line 31 Then `check(...)` is always called and `value` is always false. I _think_ because in this context 0 is always interpreted as a `int` instead of a pointer to `C::contract_f_<0>`. On Sat, Mar 27, 2010 at 10:55 PM, Jeffrey Hellrung <jhellrung@ucla.edu> wrote:
Compiles fine for me (MSVC9, Vista).
I have not tried the code on MSVC yet -- it's good it works on MSVC. I get the error with GCC/Ubuntu (what should the C++ ISO standard behavior be? error or not?).

On 28 March 2010 15:51, Mathieu - <ptr.jetable@gmail.com> wrote:
I have not tried the code on MSVC yet -- it's good it works on MSVC. I get the error with GCC/Ubuntu (what should the C++ ISO standard behavior be? error or not?).
What is your version of g++? It compiles fine for me on g++ 4.4.3.
My bad... Dont pay attention to my previous message it doesn't compile. (I copy / pasted the wrong code...)

On Sun, Mar 28, 2010 at 9:54 AM, Mathieu - <ptr.jetable@gmail.com> wrote:
What is your version of g++? It compiles fine for me on g++ 4.4.3. My bad... Dont pay attention to my previous message it doesn't compile. (I copy / pasted the wrong code...)
OK, anyways I am using g++ (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu4).

AMDG Lorenzo Caminiti wrote:
Unfortunately, it does not work (that is the first thing I tried...). If I change the `value` evaluation to:
sizeof(check(make(), 0)) == sizeof(true_t); // line 31
Then `check(...)` is always called and `value` is always false. I _think_ because in this context 0 is always interpreted as a `int` instead of a pointer to `C::contract_f_<0>`.
Okay. You might look at how https://svn.boost.org/trac/boost/ticket/861 solves the problem. In Christ, Steven Watanabe

On Sun, Mar 28, 2010 at 10:44 AM, Steven Watanabe <watanabesj@gmail.com> wrote:
Okay. You might look at how https://svn.boost.org/trac/boost/ticket/861 solves the problem.
Thanks, I'll study that. Also I found this GCC ticket where there is a discussion on this error being correct behavior, a g++ bug, a standard defect, etc. http://gcc.gnu.org/ml/gcc-bugs/2005-06/msg01288.html

On Sun, Mar 28, 2010 at 10:44 AM, Steven Watanabe <watanabesj@gmail.com> wrote:
Okay. You might look at how https://svn.boost.org/trac/boost/ticket/861 solves the problem.
Indeed BOOST_MPL_HAS_TEMPLATE_XXX_TRAIT_DEF() does what I need but I still get the same "default parameter not yet parsed" error if I use this macro at *class* scope -- see below. The Boost.MPL doc indicates this macro should be used at namespace scope (and that works just fine). However, I need to use it to declare the metafunction at class scope -- is there a way to do that? For simplicity, here I am using BOOST_MPL_HAS_XXX_TRAIT_DEF() and I have remove the `Z` template parameter of `contract_f_`. If the macro was to work at class scope than I would use `BOOST_MPL_HAS_TEMPLATE_XXX_TRAIT_DEF()` from the Boost.MPL path indicated by Steven in order to support the `Z` template parameter. $ g++ -Wall -Werror test/noinherit/07.cpp test/noinherit/07.cpp: In instantiation of ‘const bool z::has_contract_f_<x, mpl_::bool_<false> >::value’: test/noinherit/07.cpp:17: instantiated from ‘z::has_contract_f_<x, mpl_::bool_<false> >’ test/noinherit/07.cpp:22: instantiated from here test/noinherit/07.cpp:17: error: the default argument for parameter 1 of ‘static char (& z::has_contract_f_<T, fallback_>::gcc_3_2_wknd::test(const volatile boost::mpl::aux::type_wrapper<U>*, boost::mpl::aux::type_wrapper<typename U::contract_f_>*))[2] [with U = x, T = x, fallback_ = mpl_::bool_<false>]’ has not yet been parsed // File test/noinherit/07.cpp #include <boost/mpl/has_xxx.hpp> #include <iostream> struct x { virtual void f() {} struct contract_f_ {}; }; struct y { void g() {} struct contract_g_ {}; }; struct z: x, y { BOOST_MPL_HAS_XXX_TRAIT_DEF(contract_f_) void f() {} struct contract_f_ {}; static const bool bx = has_contract_f_<x>::value; static const bool by = has_contract_f_<y>::value; }; int main() { std::cout << z::bx << std::endl; std::cout << z::by << std::endl; return 0; } Thanks, Lorenzo

Hello, On Sun, Mar 28, 2010 at 3:10 PM, Lorenzo Caminiti <lorcaminiti@gmail.com> wrote:
Indeed BOOST_MPL_HAS_TEMPLATE_XXX_TRAIT_DEF() does what I need but I still get the same "default parameter not yet parsed" error if I use this macro at *class* scope -- see below.
I was able to get around this problem by always passing the 2nd parameter using member() without using the default parameter 0 -- see code below. 1) This does not give the GCC "default parameter not yet parsed" error (it compiles fine on both GCC and MVSC). 2) This can be used either at namespace or at class scope (while BOOST_MPL_HAS_TEMPLATE_XXX_TRAIT_DEF() cannot be used at class scope). 3) Should Boost.MPL consider using a similar technique to allow to use BOOST_MPL_HAS_TEMPLATE_XXX_TRAIT_DEF() within class scope? // Check if class T has a member named name (using SFINAE). // Must use internal symbols for T and U to aovid name clashes at class scope. template<class contract_T_> class has_contract_f_ { typedef char yes; typedef char (&no)[2]; static contract_T_* object(); // Using default param 0 instead of member() does not work on GCC. template<class contract_U_)> static typename contract_U_::name* member(contract_U_*); static int member(...); template<contract_U_> static yes tester(contract_U_*, typename contract_U_::name*); static no tester(...); public: static const bool value = sizeof(tester(object(), member(object()))) == sizeof(yes); typedef boost::mpl::bool_<value> type; }; Thanks to everyone for your suggestions on this! Lorenzo P.S. I am not sure the GCC "default parameter not yet parsed" error I got is compliant with ISO C++ standard (because of http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21903 and because the code with the default parameter 0 compiles just fine under MSVC). Therefore, I submitted a GCC ticket on this http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43561.

On Sun, Mar 21, 2010 at 2:30 PM, Mathias Gaunard <mathias.gaunard@ens-lyon.org> wrote:
Lorenzo Caminiti wrote:
Is there a way I can check if a class has a given member function using metaprogramming?
Yes.
Can you please point me to some code that shows how to do this? Thanks a lot. Lorenzo

--- On Sun, 3/21/10, Mathias Gaunard wrote:
Lorenzo Caminiti wrote:
Is there a way I can check if a class has a given member function using metaprogramming?
Yes.
For my edification, I could use a hint or two on how to do this. It will really help out with my concept checking code. Cromwell D. Enage
participants (16)
-
Andrew Sutton
-
Biin Ilya
-
Cromwell Enage
-
DE
-
Ilya Biin
-
Ingo Loehken
-
Jeffrey Hellrung
-
joel falcou
-
Lorenzo Caminiti
-
Marshall Clow
-
Mathias Gaunard
-
Mathieu -
-
Scott McMurray
-
Steven Watanabe
-
vicente.botet
-
Биин Илья