By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,857 Members | 1,793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,857 IT Pros & Developers. It's quick & easy.

Convoluted template declarations

P: n/a
I'm exploring the use of type traits (which, I hasten to say, I've
hardly ever used before) as a way to help simplify some complex
special-case logic in an existing codebase. I'm finding that I'm
running into some of the sharp corners of the C++ template facility.
I'm hoping someone can answer a couple of questions about the following
code snippet:

=====

template <
class D, template <D> class S,
template<D, S> struct ProblemTraits,
template<ProblemTraits> struct E

struct MetaTraits {
typedef typename D Data;
typedef typename S Solution;
typedef typename E Engine;
};

=====

.... I've tried pretty much every variation I can on this, and for
naught. Does anyone know the necessary incantation?

The task is to produce a framework for AI problems which can be
addressed by search methods. Any given engine for computing solutions
will need to know the type of the data it's operating upon, and the
type of the solutions it's generating: hence the existence of
ProblemTraits. Likewise, there are many kinds of engines which have
their solutions generate new potentials in the same neighborhood, which
means their solutions have to be able to reflect into the data.
Finally, the runtime system needs to know the types of all three
components (data, solutions and engine), hence the metatrait which
encompasses ProblemTrait<D, S> and Engine<ProblemTrait<D, S> >.

Of course, trying to hook up incompatible Engines to incompatible
ProblemTraits should cause the compile to blow up, as will incompatible
solutions to incompatible data--that's a feature I'm looking forward
to, since right now we're catching these things at runtime.

Thanks in advance for any help you can give. :)

Sep 4 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Robert J. Hansen wrote:
I'm exploring the use of type traits (which, I hasten to say, I've
hardly ever used before) as a way to help simplify some complex
special-case logic in an existing codebase. I'm finding that I'm
running into some of the sharp corners of the C++ template facility.
I'm hoping someone can answer a couple of questions about the following
code snippet:

=====

template <
class D, template <D> class S,
template<D, S> struct ProblemTraits,
template<ProblemTraits> struct E

struct MetaTraits {
typedef typename D Data;
typedef typename S Solution;
typedef typename E Engine;
};

=====

... I've tried pretty much every variation I can on this, and for
naught. Does anyone know the necessary incantation?


Well it's kind of hard to follow what you are wanting to do but

1) struct is illegal in the above code, it must be class
2) the syntax of your template template parameters is wrong (I assume
that is what you want)
3) typename is unnecessary in the typedefs
4) You must supply parameters for S and E in the typedefs

I would say that what you want is this

template <
class D,
template <class> class S,
template <class, class> class ProblemTraits,
template <class> class E>
struct MetaTraits {
typedef D Data;
typedef S<D> Solution;
typedef E< ProblemTraits< D, S<D> > > Engine;
};

It does at least compile.

john
Sep 4 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.