473,322 Members | 1,232 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

partial template specialization

Here is the code that I currently have:

template <typename type, typename ret>
struct XdrFunctionType
{
typedef type Type;
typedef ret (*Policy)(XDR*, Type*);
};

template <typename type, typename ret, typename XdrFunctionType<type,
ret>::Policy>
struct XdrPolicy
{
typedef type Type;
typedef XdrFunctionType<type, ret>::Policy Policy;
};

=====================

I want to specialize XdrPolicy template for ret type of bool and ret type of
bool_t.
In other words, I don't want the clients of XdrPolicy to have to enter 3
template parameters but rather only two: the "type" and the "Policy"
function. I want the "ret" type to be implicitly known somehow - is that
possible with what I have or with slight variation from it.

Thanks.
Jul 19 '05 #1
2 2108

"skscpp" <sk*****@hotmail.com> wrote in message
news:bl**********@news.lsil.com...
Here is the code that I currently have:

template <typename type, typename ret>
struct XdrFunctionType
{
typedef type Type;
typedef ret (*Policy)(XDR*, Type*);
};

template <typename type, typename ret, typename XdrFunctionType<type,
ret>::Policy>
struct XdrPolicy
{
typedef type Type;
typedef XdrFunctionType<type, ret>::Policy Policy;
};

=====================

I want to specialize XdrPolicy template for ret type of bool and ret type of bool_t.
In other words, I don't want the clients of XdrPolicy to have to enter 3
template parameters but rather only two: the "type" and the "Policy"
function. I want the "ret" type to be implicitly known somehow - is that
possible with what I have or with slight variation from it.


Perhaps I'm misunderstanding, but note that template
arguments can be defaulted. If you want to default
only one of three, it needs to be last.

template<typename A, typename B, typename C = T>

-Mike
Jul 19 '05 #2

"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:7q******************@newsread3.news.pas.earth link.net...

"skscpp" <sk*****@hotmail.com> wrote in message
news:bl**********@news.lsil.com...
Here is the code that I currently have:

template <typename type, typename ret>
struct XdrFunctionType
{
typedef type Type;
typedef ret (*Policy)(XDR*, Type*);
};

template <typename type, typename ret, typename XdrFunctionType<type,
ret>::Policy>
struct XdrPolicy
{
typedef type Type;
typedef XdrFunctionType<type, ret>::Policy Policy;
};

=====================

I want to specialize XdrPolicy template for ret type of bool and ret type
of
bool_t.
In other words, I don't want the clients of XdrPolicy to have to enter 3
template parameters but rather only two: the "type" and the "Policy"
function. I want the "ret" type to be implicitly known somehow - is

that possible with what I have or with slight variation from it.


Perhaps I'm misunderstanding, but note that template
arguments can be defaulted. If you want to default
only one of three, it needs to be last.

template<typename A, typename B, typename C = T>

-Mike


You are correct. However, my third parameter depends on my 2nd paramater.
I guess there isn't a way to overcome this. Well, I don't necessarily have
to use "default argument" scheme.

Thanks.
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Paul MG | last post by:
Hi Template partial specialization always seems like a fairly straightforward concept - until I try to do it :). I am trying to implement the input sequence type (from Stroustrup section...
9
by: Philip Lawatsch | last post by:
Hi I'd like to implement some kind if type traits myself, but I have to support broken compilers (like visual studio) that do not support Partial Specialization. My first shot was something...
8
by: Agent Mulder | last post by:
Hi group, I have a problem with partial template specialization. In the code below I have a template struct Music with one method, play(), and three kinds of music, Jazz, Funk and Bach. When I...
1
by: BekTek | last post by:
I'm still confused about the template partial specialization which is used in many libraries.. due to lack of introduction for beginner.. Could you tell me about that in short? Thanks in...
5
by: Levent | last post by:
Hi, Why doesn't this work? (tried with gcc 3.3.3 and VC++ 7.1): #include <iostream> template<class T, unsigned N> struct Foo { void func(); }; template<class T, unsigned N>
6
by: wkaras | last post by:
I tried a couple of compilers, and both gave errors compiling this: template <bool fin, typename T> T foo(T val); template <typename T> T foo<true, T>(T val) { return(val); } But both gave...
9
by: Marek Vondrak | last post by:
Hello. I have written the following program and am curious why it prints "1" "2". What are the exact effects of explicitly providing function template parameters at the call? Is the second...
9
by: Greg | last post by:
Hi, I would like to specify behavior of a class member relatively to template implemetation. It works in usual cases but it seems to fail with to templates when one of the two is specified... ...
10
by: jason.cipriani | last post by:
I never seem to be able to get this right. Here I have some code: template <typename T, int Nclass A { void f (T); }; template <typename Tvoid A<T,1>::f (T) { } template <typename Tvoid...
1
by: Ioannis Gyftos | last post by:
Hello, First the code :) /////////////////////////////////////////////////////////////////////////////////// // in another header file namespace LJC{
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.