Boost logo

Boost :

From: Daniel Walker (daniel.j.walker_at_[hidden])
Date: 2007-03-31 20:13:47


On 3/31/07, Daniel Walker <daniel.j.walker_at_[hidden]> wrote:
> On 3/30/07, Guillaume Melquiond <guillaume.melquiond_at_[hidden]> wrote:
> >
> > I am not sure if it will help you though, as I don't know if you can afford to
> > protect the class you want to test (bar) into a dummy template (foo),
> > so that a
> > substitution happens. No template typedef...
>
> OK, I think I got it. The trick was getting the "dummy" template.
>

I think I just found a workaround for msvc as well. The workaround
relies on a bug I noticed while working on this involving member
templates with no required parameters (all the parameters have
defaults). I worked around this problem, and I'll have a comment in my
final patch describing it. Anyway, I think this bug can be used to
work around the issue of rejecting types with member templates that
have the correct name but incorrect number of arguments. The following
code works on msvc 8.0 and 7.1.

typedef char (&yes)[1];
typedef char (&no) [2];

typedef void substitute_tag;
template< template< class U, class V > class T >
struct binary_template_substitute {
   typedef substitute_tag type;
};

template<class T, class T0, class T1, class U = substitute_tag>
struct has_xxx_impl {
   static const bool value = false;
};

template<class T, class T0, class T1>
struct has_xxx_impl<
   T, T0, T1
 , typename binary_template_substitute<
       typename T::template xxx<>
>::type
> {
   static const bool value = true;
};

template<class T, class T0, class T1>
struct has_xxx
   : has_xxx_impl<T, T0, T1> {};

struct foo {
  template<class U, class V> struct xxx;
};

struct bar {
  template<class U, class V> struct yyy;
};

struct baz {
  template<class U> struct xxx;
};

int main()
{
    int assert_has_xxx[has_xxx<foo, int, int>::value];
    int assert_not_xxx[!has_xxx<bar, int, int>::value];
    int assert_not_unary[!has_xxx<baz, int, int>::value];
}

On Monday I'm going to try to incorporate this into my has_xxx for
templates implementation, run through all my test cases, and see if I
can submit a revised patch.

Daniel


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