Boost logo

Boost :

From: Mats Nilsson (mats.nilsson_at_[hidden])
Date: 2002-04-05 04:17:10

Sorry if this list is wrong for this topic. Feel free to direct me

I'm trying to make use of a Loki::Typelist to represent a collection of
metadata for a data marshaller.

The types that I place in the Typelist are typically template

I have found myself in a position where I need to locate an entry in a list
by its template. I've come up with something that doesn't work. It always
finds a match in the first element in the typelist.


        #include <loki/Typelist.h>

        template <class T> struct Foo {
          typedef T Result;

        template <class T> struct Bar {
          typedef T Result;

        struct DefaultFallbackType {
          typedef char Result;

        typedef TYPELIST_2(Bar<int>, Foo<float>) L;

I want to search L for the first type that is a instantiation of Foo:

        typedef LocateTemplateType<L, Foo, DefaultFallbackType>::Result::Result

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>.

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 };

        template <class TList,
                  template <class> class Template,
                  class Default> struct LocateTemplateType;

        template <template <class> class Template,
                  class Default>
        struct LocateTemplateType<Loki::NullType, Template, Default> {
          typedef Default Result;

        template <class Head, class Tail, template <class> class Template, class
        struct LocateTemplateType<Loki::Typelist<Head, Tail>, Template, Default> {
          typedef Loki::Select<IsTemplateSpecialization<Template, Head>::value,
                       typename LocateTemplateType<Tail,
>::Result Result;



Boost list run by bdawes at, gregod at, cpdaniel at, john at