It is possible to construct a static vector with an initializer list of mismatching size

Issue #202 wontfix
Mikhail Katliar created an issue

Example:

#include <blaze/Math.h>
#include <iostream>

int main(int, char **)
{
    blaze::StaticVector<double, 4> v4 {1., 2., 3.};
    std::cout << v4 << std::endl;

    return 0;
}

Output:

(           1 )
(           2 )
(           3 )
(           0 )

Expected behavior: an exception is thrown or a compile-time error is generated.

Comments (4)

  1. Klaus Iglberger

    Hi Mikhail!

    I sounds like you feel that you fell into a trap. We are sorry for that. However, the according StaticVector constructor works as documented:

    The vector elements are initialized by the values of the given initializer list. Missing values are initialized as default. Note that in case the size of the initializer list exceeds the size of the vector, a std::invalid_argument exception is thrown.

    Thus from our point of view this is not a bug, but the code works as documented and specified. Please note that the semantics of this constructor are identical to the semantics of the constructors that accept arrays.

    Since the constructor works as documented and since changing the behavior of the constructor could break existing code, we will not change the existing semantics.

    Best regards,

    Klaus!

  2. Mikhail Katliar reporter

    Hello Klaus,

    thanks for the explanation. I have missed this part in the documentation somehow.

  3. Klaus Iglberger

    Hi Mikhail!

    I quoted from the complete documentation that you can download alongside the source code. Alternatively, you can also take a look at the Doxygen documentation in the source code itself. These sources are much more complete than the wiki or the tutorial. However, you make a good point. I will add this piece of information to both the wiki and the tutorial. Thanks a lot for the hint,

    Best regards,

    Klaus!

  4. Log in to comment