behavior conditional on template argument

Hello, I have a template function template <typename M> void f(const M&) { // call M.f1() // call M.f2() // some Ms have a function f1Andf2() which does f1()+ f2() work faster // how can I write code that runs f1Andf2() if it's there // otherwise runs f1() then f2() } regards,

Hi,
You can use enable_if to let the compiler decide which one it should
instantiate. And the argument will be a custom defined type trait. I
think there are facilities to automatically define it on the presence
of a type, there may be soemthing for fucntions as well, but I don't
remember where they live (MPL ?)
Matthieu
2009/1/21 Hicham Mouline
Hello,
I have a template function
template <typename M> void f(const M&) { // call M.f1() // call M.f2()
// some Ms have a function f1Andf2() which does f1()+ f2() work faster // how can I write code that runs f1Andf2() if it's there // otherwise runs f1() then f2() }
regards, _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Information System Engineer, Ph.D. Website: http://matthieu-brucher.developpez.com/ Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92 LinkedIn: http://www.linkedin.com/in/matthieubrucher

You can use enable_if to let the compiler decide which one it should instantiate. And the argument will be a custom defined type trait. I think there are facilities to automatically define it on the presence of a type, there may be soemthing for fucntions as well, but I don't remember where they live (MPL ?)
Here it is: http://www.nabble.com/compile-time-check-that-a-member-function-exists-td185...
participants (3)
-
Hicham Mouline
-
Igor R
-
Matthieu Brucher