H
Herby
I need to define my own types and arrays of these types.
These types are for the most part extensions of the built in types and
need to provide all the basic operations of arithmetic and relational.
If i was using C++ I would overload the operators against my types and
use STL Vector etc.
No problem. No performance costs. No virtual functions, no casting
etc.
Performance is a big issue for us.
The solution hints of the use of templates. As these arrays must be
publicly available, implies i need to use generics. But due to the
nature of how these work they cannot work directly with the basic
operators.
The following is what i have come up with:
interface class IType
{
public:
virtual IType^ Add( IType^ rhs );
};
-------------------------------------------------------------------
ref class CodeType : public IType
{
public:
CodeType(void);
~CodeType(void);
virtual IType^ Add( IType^ rhs );
private:
System::String^ mCode;
};
==========================================
generic<typename T1>
where T1: IType
ref class Vector : public List<T1>
{
public:
Vector(void);
Vector<T1>^ operator+( Vector<T1>% rhs );
};
Is this the best solution?
It seems like alot of virtual calls, indirection and casting to me.
If STL.NET was available, no doubt, i would simply use that. So im
kind of trying to simulate what STL.NET would have provided if it was
available?
Is this solution right or wrong?
Can it be improved upon in terms of performance etc?
Thanks in advance.
These types are for the most part extensions of the built in types and
need to provide all the basic operations of arithmetic and relational.
If i was using C++ I would overload the operators against my types and
use STL Vector etc.
No problem. No performance costs. No virtual functions, no casting
etc.
Performance is a big issue for us.
The solution hints of the use of templates. As these arrays must be
publicly available, implies i need to use generics. But due to the
nature of how these work they cannot work directly with the basic
operators.
The following is what i have come up with:
interface class IType
{
public:
virtual IType^ Add( IType^ rhs );
};
-------------------------------------------------------------------
ref class CodeType : public IType
{
public:
CodeType(void);
~CodeType(void);
virtual IType^ Add( IType^ rhs );
private:
System::String^ mCode;
};
==========================================
generic<typename T1>
where T1: IType
ref class Vector : public List<T1>
{
public:
Vector(void);
Vector<T1>^ operator+( Vector<T1>% rhs );
};
Is this the best solution?
It seems like alot of virtual calls, indirection and casting to me.
If STL.NET was available, no doubt, i would simply use that. So im
kind of trying to simulate what STL.NET would have provided if it was
available?
Is this solution right or wrong?
Can it be improved upon in terms of performance etc?
Thanks in advance.