From: tohava on
I would like to have several classes which do the following:
- HasSymbol<T>::value is true iff T has a symbol called f
- HasFunction<T>::value is true iff T has a function called f
- HasFunctionWithReturnType<T, S>::value is true iff T has a function
called f which returns T
- HasFunctionWithThreeParams<T>::value is true iff T is a function
accepting 3 params
- HasFunctionWithPrototype<T, ???>::value is true iff T has a
prototype given somehow through the question marks

has this been done before?

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Jeffrey Schwab on
On 2010-02-03 03:48:34 -0500, tohava said:

> I would like to have several classes which do the following:
> - HasSymbol<T>::value is true iff T has a symbol called f
> - HasFunction<T>::value is true iff T has a function called f
> - HasFunctionWithReturnType<T, S>::value is true iff T has a function
> called f which returns T
> - HasFunctionWithThreeParams<T>::value is true iff T is a function
> accepting 3 params
> - HasFunctionWithPrototype<T, ???>::value is true iff T has a
> prototype given somehow through the question marks
>
> has this been done before?

Yes, using SFINAE; see Boost enable_if.


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Mathias Gaunard on
On Feb 3, 2:48 pm, tohava <toh...(a)gmail.com> wrote:
> I would like to have several classes which do the following:
> - HasSymbol<T>::value is true iff T has a symbol called f
> - HasFunction<T>::value is true iff T has a function called f
> - HasFunctionWithReturnType<T, S>::value is true iff T has a function
> called f which returns T
> - HasFunctionWithThreeParams<T>::value is true iff T is a function
> accepting 3 params
> - HasFunctionWithPrototype<T, ???>::value is true iff T has a
> prototype given somehow through the question marks
>
> has this been done before?

Yes, this can be done using SFINAE, albeit it does require a few
tricks and doesn't perfectly work (you can't detect constructors, for
example).
In C++0x, however, you can use SFINAE to test whether arbitrary
expressions are valid, which makes it much better as you can consider
conversions etc.


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Jeffrey Schwab on
On 3/4/10 3:06 PM, Mathias Gaunard wrote:
> On Feb 3, 2:48 pm, tohava<toh...(a)gmail.com> wrote:
>> I would like to have several classes which do the following:
>> - HasSymbol<T>::value is true iff T has a symbol called f
>> - HasFunction<T>::value is true iff T has a function called f
.....
>> has this been done before?

> Yes, this can be done using SFINAE, albeit it does require a few
> tricks and doesn't perfectly work (you can't detect constructors, for
> example).
> In C++0x, however, you can use SFINAE to test whether arbitrary
> expressions are valid, which makes it much better as you can consider
> conversions etc.

Mathias, I was not aware of the SFINAE improvements. Could you please
provide a link, or some relevant code that works in 0x but not in 98?

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Mathias Gaunard on
On Mar 5, 2:25 pm, Jeffrey Schwab <j...(a)schwabcenter.com> wrote:

> Mathias, I was not aware of the SFINAE improvements. Could you please
> provide a link, or some relevant code that works in 0x but not in 98?

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2634.html


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]