Operator overloading -- lets collect some use cases

Bill Baxter wbaxter at gmail.com
Mon Jan 5 12:28:08 PST 2009


On Tue, Jan 6, 2009 at 1:10 AM, Weed <resume755 at mail.ru> wrote:
> In that example with matrices
> (http://www.dsource.org/projects/openmeshd/browser/trunk/LinAlg/linalg/MatrixT.d,
> template MultReturnType (ArgT)) the returned type of matrices needed to
> be altered in void (in the pointer on void). And add check by list on
> types to make the general for all matrices and other structs (vectors
> etc.) in compile time. That is to imitate a base virtual class.
> As a whole so, but I am did not check it.

I don't think this is true.  But I have trouble understanding your
English, so it's possible I've misunderstood.

It's a little more complicated to write, but MatrixT could accept an
extra 'traits' template parameter that describes things like the
return type from multiplication.   That parameter can also implement a
generic interface for querying sizes and accessing elements of
matrices.  If you do that, then the types don't have to be hard coded
like they are there.  You can also set it up so that if the user
doesn't supply such a template parameter then a default one is used
which knows about some types (basically extract that MultReturnType
logic out into part of a separate default traits template).

--bb



More information about the Digitalmars-d mailing list