|
Boost Users : |
From: John Pretz (jpretz_at_[hidden])
Date: 2008-07-22 13:56:32
Hi,
I'm pretty new to boost. I want to write some code with a compile-time
check whether a member function exists or not. The code below shows
kinda what I need except I'd obviously like to avoid a specialized
template for each class that I use.
Can anybody point me in the right direction?
Thanks,
John
****************************************
#include <iostream>
using namespace std;
struct WithMemberGo
{
void Go() const {cout<<__PRETTY_FUNCTION__<<" going...."<<endl;}
};
struct WithoutGo
{
};
template <class T>
void CallGoIfItExists(const T& t){
t.Go();
}
// I want to avoid having to specialize this function for every class
without the
// right member function.
template <>
void CallGoIfItExists<WithoutGo>(const WithoutGo&){
cout<<"not going anywhere...."<<endl;
}
int main(){
WithMemberGo with;
CallGoIfItExists(with);
WithoutGo without;
CallGoIfItExists(without);
}
-- John Pretz -- P-23, MS H803 Los Alamos National Lab Los Alamos, NM 87545 Phone: (505)665-5847 Fax: (505)665-4121
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net