473,472 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Convoluted template declarations

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
1 1356
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Xenos | last post by:
The new version of GCC is out and in its list of changes, it talks about the C++ Standard's requirements for using the typename and template keywords to disambiguate dependent names. I'm use to...
4
by: Sergei | last post by:
I ran into this problem. I needed to create an entry for access to a library of functions that are "extern C", and I just can't find the right syntax, if it exists at all ( I am using MSVC...
0
by: Leslaw Bieniasz | last post by:
Cracow, 16.09.2004 Hi, I have a problem with compiling the following construction involving cross-calls of class template methods, with additional inheritance. I want to have three class...
3
by: sks | last post by:
Hello all Is the usage of extern keyword valid for telling the compiler to NOT instantiate a template and to link it from an another binary? For example: Suppose module A's binary contains a...
1
by: petschy | last post by:
hello, i've run into an error when qualifying a copy ctor 'explicit'. the strange thing is that i get a compiler error only if the class is a template and declare the variable as X<Zx = y....
0
by: anto.anish | last post by:
Hi , Since, i did not want to write all instantiations in Source file of all template methods for various different datatypes that my client might use, Instead, i choose to write implementation...
0
by: anto.anish | last post by:
Hi , Since, i did not want to write instantiations in Source file of all template methods for various different datatypes that my client might use, i choose to write implementation of template...
1
by: anto.anish | last post by:
Hi , Since, i did not want to write explicit instantiations in Source file of all template methods for various different datatypes that my client might use, i choose to write implementation of...
21
by: H9XLrv5oXVNvHiUI | last post by:
Hi, I have a question about injecting friend functions within template classes. My question is specific to gcc (version 3.4.5) used in combination with mingw because this code (or at least code...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.