Default template parameters for policy based design

A

Arkaitz Jimenez

Hi all,
Working with the default parameters of a template class:

template <class policy1=defaultPolicy> myClass{}
I'd like as a lib user to be able to instantiate it without lt and gt
symbols <> or with them if a policy change is required.
Say:
//Default
myClass obj;
//Non-DefaultPolicy
myClass<Non-DefaultPolicy> obj;

I don't know if possible but maybe using typedefs is it possible to go
for a second typename that I can instantiate that way.
Currently it is this way:
//Default
myClass<> obj; // Note the "<>"
//Non-DefaultPolicy
myClass<Non-DefaultPolicy> obj;

Thanks

Arkaitz
 
V

Victor Bazarov

Arkaitz said:
Working with the default parameters of a template class:

template <class policy1=defaultPolicy> myClass{}
I'd like as a lib user to be able to instantiate it without lt and gt
symbols <> or with them if a policy change is required.
Say:
//Default
myClass obj;
//Non-DefaultPolicy
myClass<Non-DefaultPolicy> obj;

I don't know if possible but maybe using typedefs is it possible to go
for a second typename that I can instantiate that way.

AFAIK, not possible. A template-name has to be followed by the angle
brackets if you want to instantiate that template. And you can't
declare a typedef that has the same name as a template, IIRC.
Currently it is this way:
//Default
myClass<> obj; // Note the "<>"
//Non-DefaultPolicy
myClass<Non-DefaultPolicy> obj;

Yes, what's so bad about the "<>" after the template with the default
argument?

V
 
A

Arkaitz Jimenez

Yes, what's so bad about the "<>" after the template with the default
argument?

V

Not that it is inherently bad, but wanted to "hide" the reality of
using a template until the user of the lib is aware of the available
policies and the rest of the puzzle.

Thanks

Arkaitz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top