Boost logo

Boost :

From: Esa Ilari Vuokko (esa.vuokko_at_[hidden])
Date: 2002-04-05 13:41:28


From: "Mats Nilsson" <mats.nilsson_at_[hidden]>
> I want to search L for the first type that is a instantiation of Foo:
>
> typedef LocateTemplateType<L, Foo, DefaultFallbackType>::Result::Result
> XXX;
>
> I have tried to define this template like this, but it is not correct in
> some way. With the code below and gcc 2.95.3-5 cygwin, XXX evaluates to a
> Bar<int> instead of a Foo<float>.

I tested your code briefly and it seems to work in gcc3.0.3, but not in
2.95.3-6 (mingw special.) Guess it is nice quiet compiler bug then ;)
 
> Can anyone spot the error?
>
> template <template <class> class Template,
> class OtherType>
> struct IsTemplateSpecialization {
> enum {value = false };
> };
>
> template <template <class> class Template,
> class X>
> struct IsTemplateSpecialization<Template, Template<X> > {
> enum { value = true };
> };

I replaced these with function call/sizeof trick. It seems to work,
atleast for this small typelist.

Good luck,
Esa.

namespace detail {
    typedef char(&tag_yes)[1];
    typedef char(&tag_no)[2];
    template<template<class> class Type_> struct IsSpecHelper {
        template<class T_> static
        tag_yes impl(Type_<T_>*);
        static tag_no impl(...);
    };
}
template <template <class> class Template, class Type>
struct IsTemplateSpecialization {
private:
    typedef detail::IsSpecHelper<Template> help;
    enum {
        yes = sizeof(detail::tag_yes),
        q = sizeof(help::impl(static_cast<Type*>(0)))
    } ;
public:
    enum { value = (q == yes) } ;
};


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