Boost logo

Boost :

From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2007-08-30 09:56:44

Daryle Walker wrote:
> We have some class templates in forms like:
> //==========================================================
> template <unsigned X> struct my_test;
> template <> struct my_test<0u> {};
> template <unsigned X>
> struct my_test { typedef my_test<(X - 1u)> type; };
> //==========================================================
> IOW, the traits express their result as a type, but omit the type for
> out-of-domain values.
> I was looking at the enable_if documentation and
> I was wondering if we can use SFINAE to create functions and/or function
> templates that will test manifestations of "my_test," but skip the test
> for out-of-domain values without have to explicitly exclude the values.

If I understood correctly, ideally, you would like to use SFINAE with a
test that says "is this expression valid?".
Such a facility would be quite awesome, indeed, and allowate real duck
typing with fallback. It would be even better than concepts and such.
(maybe concepts allow this actually?)

You could probably do that by exposing basic compile-time reflection
data through MPL containers for each types and operation.
I have no idea, though, how you could write the expressions quite easily
so that validity checks are performed automatically according to the
reflection data.

Boost list run by bdawes at, gregod at, cpdaniel at, john at