[EnableIf?] Seeking an example....
Somewhere in the Boost headers, or maybe the Boost documentation I have seen a bit of code which uses SFINAE, and also possibly the enable_if header to select either a find class method or find global template depending on what's available. It might have been written by Eric. I can't find it now,maybe it's not there any more, but if anyone can point me to it I'd really appreciate it! Thanks in advance, - Rob.
Robert Jones wrote:
Somewhere in the Boost headers, or maybe the Boost documentation I have seen a bit of code which uses SFINAE, and also possibly the enable_if header to select either a find class method or find global template depending on what's available.
That's compile-time detection of whether the object has some member function with a given signature or not. You can detect mostly everything but constructors and member-only operators, actually. It's too bad there isn't a Boost library to do just that. It's true that with concepts, though, it becomes less useful. There are probably bits in some places in Boost but I never knew where they were.
Mathias Gaunard a écrit :
Robert Jones wrote:
Somewhere in the Boost headers, or maybe the Boost documentation I have seen a bit of code which uses SFINAE, and also possibly the enable_if header to select either a find class method or find global template depending on what's available. That's something that was already explained indeed. Here is a way to do it. Let's say you want to test for presence of a go() method with the following prototype :
void go();
in any type :
typedef char NotFound; struct Found { char x[2]; };
template
participants (3)
-
Joel Falcou
-
Mathias Gaunard
-
Robert Jones