Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2003-01-25 07:50:37


On Sat, 25 Jan 2003 11:48:52 -0000, "John Maddock"
<jm_at_[hidden]> wrote:

>There are all kind of useful uses for is_convertible that do not involve
>converting anything as such, for example:
>
>template <class I>
>struct is_random_access_iterator
>{
>private:
> typedef typename std::iterator_traits<I>::iterator_category cat;
>public:
> BOOST_STATIC_CONSTANT(bool, value = (::boost::is_convertible<cat*,
>std::random_access_iterator_tag*>::value));
>};

Well, do you want to see if pointers are convertible?

// see function templates in one of my other posts
//
template <class I>
struct is_random_access_iterator
{
private:
   typedef typename std::iterator_traits<I>::iterator_category cat;
public:
   BOOST_STATIC_CONSTANT(bool, value =
   (sizeof(yes_type) ==
   sizeof(is_convertible<std::random_access_iterator_tag*>( (cat*)0 ))
       )
       );
       
};

Or do you want to see if I's iterator_category *is*
random_access_iterator_tag?

template <typename T>
struct is_random_access_iterator_tag {
    enum { value = false };
};

template <>
    struct
is_random_access_iterator_tag<std::random_access_iterator_tag> {
    enum { value = true };
};

template <class I>
struct is_random_access_iterator
{
private:
   typedef typename std::iterator_traits<I>::iterator_category cat;
public:
   BOOST_STATIC_CONSTANT(bool, value =
       is_random_access_iterator_tag<cat>::value;
   );
       
};

>There are lots of other similar uses, particularly for concept checks and
>the like...

I don't doubt that. But have you an example that requires this
abstract concept of "convertibility of a type" that we are not able to
define?

Genny.


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