Boost logo

Boost :

From: Stefan Slapeta (stefan_at_[hidden])
Date: 2004-07-30 02:54:20


 

> -----Original Message-----
> From: boost-bounces_at_[hidden]
> [mailto:boost-bounces_at_[hidden]] On Behalf Of Thorsten Ottosen

>
> Do you know how to make the test run for only the relevant compilers?
>

I've not found it yet, either; maybe Aleksey can help.
_However_: When you have a look at numeric/ublas, you will see that test7 is
only executed on some few compilers
(no idea, why). Of course, this could also be a defect :)

> |
> | template <class T> struct wrap {};
> |
> | // this one should disabled because it's not allowed to
> return an array:
> | template< typename T > T(* is_array_tester1(wrap<T>) )(wrap<T>);
>
> What does the line above mean in plain English :-)

It's only the half solution but it was enough to show the SFINAE problem.
The complete code looks like this:

template< typename T > T(* is_array_tester1(wrap<T>) )(wrap<T>);
char BOOST_TT_DECL is_array_tester1(...);

template< typename T> no_type is_array_tester2(T(*)(wrap<T>));
yes_type BOOST_TT_DECL is_array_tester2(...);

template< typename T >
struct is_array_impl
{
    BOOST_STATIC_CONSTANT(bool, value =
        sizeof(::boost::detail::is_array_tester2(
            ::boost::detail::is_array_tester1(
                ::boost::type_traits::wrap<T>()
                )
        )) == 1
    );
};

Here, if a function returning T can be instantiated (is_array_tester1), T
cannot be an array. This is tested by is_array_tester2.

> And why is is_array not defined as
>
> template< class T, int sz >
> true_type is_array( const T (&array)[sz] ); template< class
> T, int sz > true_type is_array( T (&array)[sz] ); no_type
> is_array( ... );
>

This was my first question, too, but the answer probably can only give any
of the authors. It could be: "does this work with open arrays?"

Stefan


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk