[Dune-devel] DenseVector, FieldVector: a couple of small changes
Ansgar Burchardt
ansgar.burchardt at tu-dresden.de
Tue Feb 12 14:29:51 CET 2019
Hi,
I was looking at DenseVector to rename some arguments[1]. While doing
so I noticed several things:
a) Why is `Traits::derived_type` used instead of just `V`?
Note that `asImp()` returns `V&` and is used to return a
`derived_type&`.
I consider adding a static_assert to ensure V == derived_type and maybe
stop using Traits::derived_type in the future.
b) Not all variants of `operator=` return a `derived_type&`. This
looks like an oversight and I plan to change that.
c) Why is FieldVector's constructor copying from a FieldVector (with
different field and size) explicit, but the one copying from a generic
DenseVector not?
d) I would like to explicitly delete functions instead of having
static_asserts, that is:
```c++
template<typename T, int N>
struct FieldVector
{
FieldVector() = default;
FieldVector(const FieldVector&) = default;
template<typename T2>
FieldVector(const FieldVector<T2, N>&) {}
template<typename T2, int N2>
FieldVector(const FieldVector<T2, N2>&) = delete;
};
void f()
{
FieldVector<double, 2> x1;
FieldVector<float, 2> x2(x1); // OK
FieldVector<double, 3> x3(x1); // error: use of deleted function
FieldVector<float, 3> x4(x1); // error: use of deleted function
}
```
instead of having only one template function with template arguments
(T2, N2) and a static_assert to make sure N2==N.
(Just not having it would mean the generic version for a DenseVector
would be used which is also wrong.)
This makes the interface explicitly state that N2==N is required
instead of having it hidden in a static_assert in the function
definition.
Ansgar
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 6519 bytes
Desc: not available
URL: <https://lists.dune-project.org/pipermail/dune-devel/attachments/20190212/2609dfcf/attachment.bin>
More information about the Dune-devel
mailing list