|
Boost : |
Subject: Re: [boost] [C++0x] Report from Frankfurt committee meeting
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2009-08-13 09:19:56
Vicente Botet Escriba wrote:
> When you talk about using SFINAE, are you thinking on the Concept Traits
> library
> (http://neoscientists.org/~tschwinger/boostdev/concept_traits/libs/concept_traits/doc)
> that Terje Slettebø and Tobias Schwinger have abandoned because the C++0x
> should have Concepts?
No, I'm thinking of using SFINAE generalized for expressions (note that
this requires a compiler which supports the feature, such as GCC 4.4+),
that is to say to put the expressions to check for directly in the
signature of the overload, be it with sizeof or decltype.
For example, to check a variant of the Callable2<F, T1, T2> concept,
template<int> struct dummy {};
template<typename T> T& make();
template<typename F, typename T1, typename T2>
char callable2_impl(dummy<sizeof(
typename F::result_type(
make<F>()(
make<T1>(),
make<T2>()
)
)
, 0)>*);
template<typename F, typename T1, typename T2>
char (&callable2_impl(...))[2];
template<typename F, typename T1, typename T2>
struct Callable2 : mpl::bool_<sizeof(callable2_impl<F, T1, T2>(0)) == 1>
{
};
Then you can just test for the Callable2 concept using enable_if or
BOOST_MPL_ASSERT. (the syntax for declaring concepts would of course use
the preprocessor instead of directly writing this)
Unfortunately using std:::result_of<F(T1, T2)>::type instead of
F::result_type doesn't work, since the substitution failure happens
within the definition of result_of, but that should be solvable.
I believe things like associated types can be integrated as well.
This isn't as nice to write as the current system Boost.ConceptCheck
uses however, which allows to use private members instead of make<T>
thingies.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk