- changed title to Using CustomVector with const arrays
Using CustomVector with const arrays
It seems currently impossible to use a cost-pointer to raw array with CustomVector
:
#include <blaze/Math.h>
int main(int argc, char ** argv)
{
using namespace blaze;
double const raw_data[3] = {1., 2., 3.};
CustomVector<double, unaligned, unpadded> c1(raw_data, 3); // <-- Compiler error!
CustomVector<double const, unaligned, unpadded> c2(raw_data, 3); // <-- Compiler error!
return 0;
}
Compiler output:
blaze_const_custom_vector.cpp:10:47: error: no matching constructor for initialization of 'CustomVector<double, unaligned, unpadded>'
CustomVector<double, unaligned, unpadded> c1(raw_data, 3);
^ ~~~~~~~~~~~
/usr/local/include/blaze/math/dense/CustomVector.h:481:20: note: candidate constructor not viable: no known conversion from 'const double [3]' to
'double *' for 1st argument
explicit inline CustomVector( Type* ptr, size_t n );
^
/usr/local/include/blaze/math/dense/CustomVector.h:485:20: note: candidate constructor template not viable: requires 3 arguments, but 2 were provided
explicit inline CustomVector( Type* ptr, size_t n, Deleter d );
^
/usr/local/include/blaze/math/dense/CustomVector.h:488:20: note: candidate constructor template not viable: requires 4 arguments, but 2 were provided
explicit inline CustomVector( Type* ptr, size_t n, size_t nn, Deleter d );
^
/usr/local/include/blaze/math/dense/CustomVector.h:490:11: note: candidate constructor not viable: requires single argument 'v', but 2 arguments were
provided
inline CustomVector( const CustomVector& v );
^
/usr/local/include/blaze/math/dense/CustomVector.h:491:11: note: candidate constructor not viable: requires single argument 'v', but 2 arguments were
provided
inline CustomVector( CustomVector&& v ) noexcept;
^
/usr/local/include/blaze/math/dense/CustomVector.h:482:20: note: candidate constructor not viable: requires 3 arguments, but 2 were provided
explicit inline CustomVector( Type* ptr, size_t n, size_t nn );
^
/usr/local/include/blaze/math/dense/CustomVector.h:480:20: note: candidate constructor not viable: requires 0 arguments, but 2 were provided
explicit inline CustomVector();
^
/usr/local/include/blaze/math/dense/CustomVector.h:717:4: error: static_assert failed "Const-qualified type detected"
BLAZE_CONSTRAINT_MUST_NOT_BE_CONST ( Type );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/blaze/util/constraints/Const.h:80:4: note: expanded from macro 'BLAZE_CONSTRAINT_MUST_NOT_BE_CONST'
static_assert( !::blaze::IsConst<T>::value, "Const-qualified type detected" )
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
blaze_const_custom_vector.cpp:11:53: note: in instantiation of template class 'blaze::CustomVector<const double, false, false, false>' requested here
CustomVector<double const, unaligned, unpadded> c2(raw_data, 3);
^
One could use const_cast<>
to strip the const-qualifier from the pointer, which is not the right thing I suppose.
What is the motivation for disallowing const-types in CustomVector
? Should the support for const-arrays be added in CustomVector
or implemented in a different class e.g. ConstCustomVector
?
Comments (9)
-
reporter -
reporter - edited description
-
reporter - edited description
-
Hi Mikhail!
Thanks for pointing out this issue with
CustomVector
. It appears to be an oversight that it is currently not possible to create aCustomVector
with a pointer to a constant array. We expect that this problem can be solved quickly and we will provide a solution shortly. Again, thanks a lot,Best regards,
Klaus!
-
-
assigned issue to
-
assigned issue to
-
- changed status to open
-
- changed status to resolved
Summary
The feature has been implemented and tested as required. It is immediately available via cloning the Blaze repository and will be officially released in Blaze 3.2.
CustomVector
It is now possible to create a
CustomVector
instance by passing a pointer to aconst
array:using namespace blaze; double const raw_data[3] = {1., 2., 3.}; CustomVector<double const, unaligned, unpadded> a(raw_data, 3);
Please note that it is necessary to explicitly
const
-qualify the type of elements!CustomMatrix
It is now also possible to create a
CustomMatrix
instance by passing a pointer to aconst
array:using namespace blaze; double const raw_data[3] = {1., 2., 3., 4., 5., 6., 7., 8., 9.}; CustomMatrix<double const, unaligned, unpadded> A( raw_data, 3, 3 );
Please note that also in this case it is necessary to explicitly
const
-qualify the type of elements! -
reporter Great, thanks for fixing it so quickly, Klaus!
-
My pleasure. Thanks for pointing out this defect!
- Log in to comment