Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2000-10-01 10:09:08


From: "John Maddock" <John_Maddock_at_[hidden]>

> Thanks to a slew of recent posts here and elsewhere regarding VC6 template
> workarounds, I've been able to get most of the type_traits library and
> hence call_traits working with VC6, in particular you can now use
> call_traits on VC6 to solve the "reference to reference" problem.

Great work!

> Dave, can you check out the latest cvs code and see if this now solves the
> problems you were having?

unfortunately, it turns out that my test case involves supplying a
pointer-to-member to some other code, and the only way to stimulate the
problem would be for the member to be a reference type. Of course, you can't
form a pointer to a reference member, so I guess that filling my request was
unneccessary in this case. I'm _sure_ someone wants this to work, though!

I presume it passes some test of yours, yes?

Appended please find a quick test I whipped up at home, with some results

> Outstanding issues:
>
> is_array is still broken, as are all the templates that perform or rely on
> type transformations -

Call that "type reductions", or something. Anybody can *add* a pointer to a
type ;->

> for example I can tell whether a type is const,
> volatile, a reference, or a pointer, but I can't see any way of stripping
> type qualifiers from a type without partial specialisation. For example
> these techniques do not permit a standard conformant iterator_traits -
even
> though we can tell that the argument is a pointer, we can't tell what it
> points to.

No, for that we still need to rely on "runtime partial specialization". You
know the drill: dispatch to different functions based on the return type of
a tagging function which should get optimized away.

helping-to-keep-^#%!-msvc-alive-for-one-more-day-ly y'rs,
dave

------
template <class T> struct assert_int_ref;
template <> struct assert_int_ref<int&>{};

template <class T> struct assert_volatile_int_ref;
template <> struct assert_volatile_int_ref<volatile int&>{};

template <class T> struct assert_const_int_ref;
template <> struct assert_const_int_ref<const int&>{};

template <class T> struct assert_const_volatile_int_ref;
template <> struct assert_const_volatile_int_ref<const volatile int&>{};

void foo()
{
    // passes
    assert_const_int_ref<boost::call_traits<const int&>::const_reference> a;

    // fails: int&, not const int&
    assert_const_int_ref<boost::call_traits<int&>::const_reference> b;

    // passes
    assert_const_int_ref<boost::call_traits<int>::const_reference> c;

    // fails catastrophically: causes ref-to-ref
    assert_const_volatile_int_ref<boost::call_traits<const volatile
int&>::const_reference> d;

    // fails(?): volatile int&, not const volatile int&
    assert_const_volatile_int_ref<boost::call_traits<volatile
int&>::const_reference> e;

    // passes
    assert_const_volatile_int_ref<boost::call_traits<volatile
int>::const_reference> f;

    // passes
    assert_const_int_ref<boost::call_traits<const int&>::reference> g;

    // passes
    assert_int_ref<boost::call_traits<int&>::reference> h;

    // passes
    assert_int_ref<boost::call_traits<int>::reference> i;

    // passes
    assert_const_int_ref<boost::call_traits<const int>::const_reference> j;

    // passes
    assert_const_int_ref<boost::call_traits<const int>::reference> k;

    // passes
    assert_const_volatile_int_ref<boost::call_traits<const volatile
int>::const_reference> l;

    // passes
    assert_volatile_int_ref<boost::call_traits<volatile int>::reference> m;

    // passes
    assert_volatile_int_ref<boost::call_traits<volatile int&>::reference> n;
};


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