I'm trying to port simple expression template to generics but I
get some strange errors. The code is shown below and the errors are:
(1) 'l_' : is not a member of 'IExpresion'
(2) syntax error : '('
generic <class Lhs, class Rhs>
where Lhs:IExpresion
where Rhs:IExpresion
ref struct Expression : public DotNetMat::IExp resion
{
typedef float tip;
Expression( Lhs% lhs, Rhs% rhs)
: l_(lhs), r_(rhs)
{
}
virtual tip% operator () (int r, int c)
{
(2) return l_.(r, c) + r_.(r, c);
}
virtual int GetRowNum()
{
(1) return l_.GetRowNum();
}
private:
Lhs l_;
Rhs r_;
};
public interface class IExpresion
{
public:
typedef System::Single tip;
virtual tip% operator () (int r, int c);
virtual int GetRowNum();
};
Any ideas how to solve this problem?
Has anyone tried to this and can this be done?
Thx a lot!
Best regards,
Zoran Stipanicev. 2 1274
"Zoran Stipanicev" <st************ *@gmail.com> wrote I'm trying to port simple expression template to generics but I get some strange errors. The code is shown below and the errors are: (1) 'l_' : is not a member of 'IExpresion' (2) syntax error : '('
It would be quite helpful to have a complete example.
Here, it is not clear what DotNetMat or IExpresion
is (it can't be the definition below because it is used
as a base class before, which requires a complete
class type)
virtual tip% operator () (int r, int c) { (2) return l_.(r, c) + r_.(r, c);
If you want the operator() you'd use l_(r,c).
}
virtual int GetRowNum() { (1) return l_.GetRowNum(); }
The diagnostic does not make sense, AFAICT. Please
get use a reproducible example.
Apart from that most reference types are not copy-constructible,
and when they are they signature usually requires a const R%.
Has anyone tried to this and can this be done?
There are many limitations in the CLR and C++/CLI as compared
to standard C++. ET exploit C++ staging capabilities. A feature
which comes at a considerable price in the CLR.
Bottom line, expression template techniques work much better
with C++ far more flexible type system. You shouldn't opt for
CLR generics unless you absolutely have to.
-hg
I forgot to delete the DotNetMat it's the namespace containing
IExpresion.
IExpresion is interface shown on the end of first message. In real
program it's included on beginning of file. I'm doing this for
faculty. Actually I don't have to do it, I just have to see if it's
possible and if it is compare performance with native c++.
Lhs (and Rhs) passed in real program is matrix and I think that would
be to much code to post. I've tried to use operatot() without the
"." but I got this error:
term does not evaluate to a function taking 2 arguments
So far I found a lot of things that can be done with templates and
can't be done with generics. Is there any thing that can be done with
generics and can't be done with templates?
Has anyone seen some got code example that show all the differences
between templates and generics, and all the things that can/can't be
done with generics?
Thx a lot!
Best regards,
Zoran Stipanicev. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Andre |
last post by:
Hi,
I've built a math library that does some matrix multiplications and
other linear algebric functions. I read some place about generics or
class templates and I was wondering if this will help me in any way? I
have structures and classes with the same logic but that which deal with
different types. Moreover, I would like to know if there are any
performance benifits or drawbacks and how templates are or can be
important to numerical...
|
by: Bob Weiner |
last post by:
Hi,
Forgive me if this has already been discussed but does C# have a construct
like C++ templates?
bob
|
by: Mr.Tickle |
last post by:
So whats the deal here regarding Generics in the 2004 release and templates
currently in C++?
|
by: Peter Oliphant |
last post by:
Is there any plan to support templates with managed code in the (near)
future? For instance, VS.NET 2005... : )
|
by: Zoran Stipanicev |
last post by:
Hi!
I've changed the code to use Apply instead of operator() and now I get
this errors:
(1) left of '.Apply' must have class/struct/union
(2) left of '.GetRowNum' must have class/struct/union
(3) 'return' : cannot convert from
'Expression<Lhs,Rhs>' to 'Expression<Lhs,Rhs>'
Cannot copy construct struct 'Expression<Lhs,Rhs>' due to
ambiguous copy constructors or no available copy constructor
| |
by: titan.nyquist |
last post by:
"At the implementation level, the primary difference is that C#
generic type substitutions are performed at runtime and generic type
information is thereby preserved for instantiated objects."
- http://msdn2.microsoft.com/en-us/library/c6cyy67b.aspx
Wonder if someone could elaborate this difference to me. I understand
performing substitutions at runtime is slow. But, it implies in c++
templates, the type information is not preserved...
|
by: Dexter |
last post by:
This Java based utility may be invoked from Java code to parse
mathematical expressions. It is useful for programmers developing
calculators, graphing utilities or other math related programs.
Download for free at http://www.thinkanddone.com/prog/java/parser.html
If the above link does not work try http://www.britishcomputercolleges.com/prog/java/parser2.html
|
by: madhu.srikkanth |
last post by:
Hi,
I came across a paper by Angelika Langer in C++ Users Journal on
Expression Templates.
In the article she had mentioned that the code snippet below used to
calculate a dot product is an expression template.
template <size_t N, class T>
class DotProduct {
|
by: puzzlecracker |
last post by:
Team,
C++ has been around since 1986, why templates are still regarded is a
new feature by most compiler vendors and not fully supported (for
example export feature). Look at other popular languages -- say Java,
CSharp --and templates , also known as generics, are fully implemented
and supported in latest releases. Yes, in C++ they are implemented
differently, yet not better. Then why C++ is so lagging behind. Can't
we get ourself...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |