|
From: | David Spies |
Subject: | Fwd: Considering adding a "dispatch" function for compile-time polymorphism |
Date: | Thu, 31 Jul 2014 22:00:55 -0600 |
In many Octave functions, we have code that does things like
NDArray nda = ov.array_value ();
and this operation succeeds if it is possible for the octave_value object OV to be converted to an NDArray object. Is it really better to have what is essentially a big switch statement that checks known types of octave_value objects? Using the switch statement means that if a new type is added that can be converted to an NDArray object, you have to modify the switch statement to make this work.
With conversions, you can make this work just by providing an array_value function in your new type.
I guess I don't understand this question because the octave_value::array_value function is implemented for more than just permutation matrices, isn't it?
Instead of an array_value function which only takes a permutation matrix
as an argument, wouldn't you prefer one which takes any matrix type as
an argument (including sparse or diagonal)?
Please point me to the code that does this.
If you are checking for each specific type and dispatching, then how
is this approach better than providing a "find" method in the
octave_value class and using a virtual function to perform the
dispatching?
I'm not dispatching to different implementations, I'm dispatch to the
same implementation with different template types. As far as I know,
that's impossible with virtual methods (because virtual methods can't be
templated)
[Prev in Thread] | Current Thread | [Next in Thread] |