473,387 Members | 1,493 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,387 software developers and data experts.

Template parameters

I have something like this:

template<typename math, typename real, typename vector, typename matrix>
void fun(real a, vector v, matrix m)
{
typedef typename math::line line;
.....
}
but real, vector and matrix are all types included in math. Is there some
technique to only supply math as a template parameter eventhough real,
vector and matrix are used as function arguments in fun?
Aug 19 '08 #1
3 1198
On 19 ago, 11:09, "saneman" <as...@asd.comwrote:
I have something like this:

template<typename math, typename real, typename vector, typename matrix>
void fun(real a, vector v, matrix m)
{
* * * * typedef typename math::line line;
* * * * .....

}

but real, vector and matrix are all types included in math. Is there some
technique to only supply math as a template parameter eventhough real,
vector and matrix are used as function arguments in fun?
Hi.

Yes, the same way you did inside the function body:

template<typename math>
void fun(typename math::real a, typename math::vector v,
typename::matrix m)
{
typedef typename math::line line;
.....

}

Probably, you also might wanna consider passing those parameter by
const-ref (or just by ref if you're to modify them). For example:
const typename math::real&.

--
Leandro T. C. Melo
Aug 19 '08 #2

but real, vector and matrix are all types included in math.
are they?
I guess std::vector, std::real and std::matrix might be. But vector, real
and matrix are not.
It's the price for using "using namespace std;", I guess.

Aug 19 '08 #3
On 19 ago, 12:19, "Gernot Frisch" <m...@privacy.netwrote:
but real, vector and matrix are all types included in math.

are they?
I guess std::vector, std::real and std::matrix might be. But vector, real
and matrix are not.
It's the price for using "using namespace std;", I guess.
I think that in this case those types are user-defined ones from the
OP. Naturally, naming a user-defined class as 'vector' might not be a
good idea.

--
Leandro T. C. Melo
Aug 19 '08 #4

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

Similar topics

3
by: Gianni Mariani | last post by:
I was a little surprised by this: It seems like the code below should not compile but the Comeau 4.3.3 compiler accepts it and the gcc 3.4(prerel) compiler rejects it and MSVC++7.1 ICE's. ...
11
by: Alexander Stippler | last post by:
Hi, I have a little problem to design some template classes in a realizable way. I have some Container classes and some Proxy classes (proxies for elements). Looks like this: // P is the...
3
by: Erik Wikström | last post by:
I've been trying for a while now to understand how template template parameters work. But I just can't wrap my head around it and was hoping that someone might help me. As best I can figure the...
6
by: rincewind | last post by:
Hi, can anybody summarise all options for partial template specialization, for all kind of parameters (type, nontype, template)? I *think* I understand options for partial specialization on...
4
by: Dan Krantz | last post by:
I have the following template to ensure that a given number (val) falls into a range (between vmin & vmax): template<typename T> T ForceNumericRange( const T& val, const T& vmin, const T& vmax)...
8
by: Paul Roberts | last post by:
Hi, I'm hoping somebody here can help me with a simple problem of template syntax. Here's an example: template<typename T, int iclass A { static int a;
8
by: Jess | last post by:
Hi, I have a template function that triggered some compiler error. The abridged version of the class and function is: #include<memory> using namespace std; template <class T>
2
by: Pierre Yves | last post by:
Hi there, Sorry for the double subject but I feel they are related. I'm not pretty sure there would be an answer but I reckon there must be a way to make it work. I would like to write the...
8
by: flopbucket | last post by:
Hi, I want to provide a specialization of a class for any type T that is a std::map. template<typename T> class Foo { // ... };
4
by: * Tong * | last post by:
First of all, thanks mlimber for answering my previous question. Now... I'm following the example in "C++ Templates: The Complete Guide", section 5.4 Template Template Parameters, and I'm...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.