Hi,
In the function body of doit, I want to assign -x to _a if x is a real
type. I want to assign conj(x) to _a if it is a complex type.
I could define
template <typename T>
class A<std::complex<T {
.....
};
But there are some redundancies between the definition class
A<std::complex<T and class A<T>.
I'm wondering if boost MPL can be without define a new class or the
class with a different template parameters.
Thanks,
Peng
template <typename T>
class A {
public:
A() {}
void doit(const T &x) {
....
}
private:
T _a;
};
int main() {
A<doublea;
double x = 0;
a.doit(x);
} 3 1300
On May 27, 6:11 am, "PengYu...@gmail.com" <PengYu...@gmail.comwrote:
Hi,
In the function body of doit, I want to assign -x to _a if x is a real
type. I want to assign conj(x) to _a if it is a complex type.
I could define
template <typename T>
class A<std::complex<T {
....
};
But there are some redundancies between the definition class
A<std::complex<T and class A<T>.
I'm wondering if boost MPL can be without define a new class or the
class with a different template parameters.
Thanks,
Peng
template <typename T>
class A {
public:
A() {}
void doit(const T &x) {
....
}
private:
T _a;
};
int main() {
A<doublea;
double x = 0;
a.doit(x);
}- Hide quoted text -
- Show quoted text -
The only way I know is to overload doit() method. I'm afraid you have
to write doit(...) method for every data type.
On May 27, 12:11 am, "PengYu...@gmail.com" <PengYu...@gmail.com>
wrote:
Hi,
In the function body of doit, I want to assign -x to _a if x is a real
type. I want to assign conj(x) to _a if it is a complex type.
I could define
template <typename T>
class A<std::complex<T {
....
};
But there are some redundancies between the definition class
A<std::complex<T and class A<T>.
I'm wondering if boost MPL can be without define a new class or the
class with a different template parameters.
Thanks,
Peng
template <typename T>
class A {
public:
A() {}
void doit(const T &x) {
....
}
private:
T _a;
};
int main() {
A<doublea;
double x = 0;
a.doit(x);
}
There is possibility to declare template to be independent of type,
but to add the partial specializations in implementation to define
that implementation for complex and real types will vary.
I will prepare the example basing on your program and will upload it
shortly.
On Sat, 26 May 2007 15:11:50 -0700, Pe*******@gmail.com wrote:
Hi,
In the function body of doit, I want to assign -x to _a if x is a real
type. I want to assign conj(x) to _a if it is a complex type.
I could define
template <typename T>
class A<std::complex<T {
....
};
But there are some redundancies between the definition class
A<std::complex<T and class A<T>.
I'm wondering if boost MPL can be without define a new class or the
class with a different template parameters.
Thanks,
Peng
template <typename T>
class A {
public:
A() {}
void doit(const T &x) {
....
}
private:
T _a;
};
int main() {
A<doublea;
double x = 0;
a.doit(x);
}
Define a template function
template<class Tvoid f(const T &x, T &a)
{
a = -x;
}
template<class Tvoid f(const std::complex<T&x, std::complex<T&a)
{
a = conj(x);
}
and call it in A::doit().
--
Markus Schoder This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ian |
last post by:
I have begun testing some code based on Chapter 1.5.1 of the book Modern C++
Design by Andrei Alexandrescu. The test code is listed below and the
compiler error message that is generated is:
...
|
by: Marc Schellens |
last post by:
I posted a similar question some time ago, but didn't get an
satisfying answer.
Lets say I have a template and five integer and two floating
types.
template <typename T> class A
{
A() {}...
|
by: John Harrison |
last post by:
I want to write a templated constructor with a non-type template argument,
like this.
class X
{
public:
X() : val(0) {}
template <int I>
X(X const&, X const&) : val(I) {}
|
by: Peter Koch Larsen |
last post by:
This question has undoubtedly come up zillions of times before, but I've not
been able to google for an answer. My problem can be reproduced as follows:
template<typename T, bool b>
struct bad...
|
by: Abhishek Saksena |
last post by:
Is it possible using Boost mpl library:-
Assume any class implementing a function "connect" with two arugments of
fixed types
class protocol1
{
connect(T0 & t0, T1 &t1 ){..} //fixed types...
|
by: Suki |
last post by:
Hi,
I'm writing a templated class, and i dont want to use the class
otherthan for some predetermined types, say, int, double etc.
This class has no meaning for typenames other than those few.
...
|
by: Joseph Turian |
last post by:
Let's say I have a function template as follows:
template<class T, class U>
foo {
...
}
However, I'd like to have different behavior if T == U.
How can I check that?
|
by: psujkov |
last post by:
Hi everybody,
let us have some class A with const static int variable var with
compile-time well-known value. let us have some function f(), which
has return type of A. and let us have some...
|
by: Kaushal |
last post by:
#include <iostream>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/find.hpp>
using namespace std ;
using namespace boost ;
template <typename numericTypes>
struct evalThis
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
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...
|
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....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
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...
| |