porting expression templates to generics

  • Thread starter Thread starter Zoran Stipanicev
  • Start date Start date
Z

Zoran Stipanicev

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::IExpresion
{
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.
 
Zoran Stipanicev said:
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.
 
Back
Top