Re: [glas] MTL3 design ? [was MTL project site is up]
From: Toon Knapen (toon.knapen_at_[hidden])
Date: 2005-02-02 11:43:35
Jeremy Graham Siek wrote:
> Hi Dave, Toon,
> On Feb 1, 2005, at 3:55 PM, David Abrahams wrote:
>>> operator= for vectors does not require both vectors to have the same
>>> size. Thus the lhs will be resized to the size of the rhs. But again
>>> this poses a problem with stack-based objects because they can't be
>>> resized. And why actually do you prefer to resize the lhs instead of
>>> requiring that both vectors have the same size?
>> I haven't given that question much thought yet, and I don't know
>> Jeremy's rationale, but I can guess: stack objects with different
>> sizes also have different types, so we can enforce incompatibility at
So since assigning stack-based vectors of different sizes produces a
(compile-time) error, it is not unexpected that assigning a vector
(heap-based or other) to a vector of a different size generates an error
(compile-time or run-time): generally assignments between vectors of
different sizes result in an error.
Additionally I think it would be more intuitive for mathematicians if we
require vectors to have the same size before assigning them
>> We can't do the same with other objects, and there's no
>> obvious reason to impose an incompatibility restriction.
resizing a vector comes with a (big) cost. I'm afraid that if the
resizing is done under the hood, people will be surprised by the
performance(-penalties) they get.
>> I can
>> imagine that it becomes quite inconvenient and even expensive in some
>> cases. For example, constructing unity and identity matrices might be
>> more painful than neccessary.
I think unity and identity matrices are rather the exception than the
rule. For instance, you neither can modify the elements in the unity and
identity matrices. So they are no regular containers like vectors and
matrices. Rather they are placeholders in an expression(-template). So I
think that for the sake of the identity and unity matrix we can
justify the drawbacks as described above.