Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Q_DECLARE_METATYPE a boost::multi_array

Tags:

c++

boost

qt

I am trying to pass a multi-dimensional array represented as boost::multi_array using Qt's signals and slots mechanism. I attempted to declare meta-type using the following piece of code:

Q_DECLARE_METATYPE(boost::multi_array<double, 2>)

However I get the following compilation errors (on MSVC 2015):

path\to\project\metatypes.h(7): error C2976: 'boost::multi_array': too few template arguments
..\..\ml_project\boost-libs\include\boost/multi_array.hpp(111): note: see declaration of 'boost::multi_array'
path\to\project\metatypes.h(7): error C2332: 'enum': missing tag name
path\to\project\metatypes.h(7): error C2065: 'Defined': undeclared identifier
path\to\project\metatypes.h(7): error C2143: syntax error: missing '>' before ';'
path\to\project\metatypes.h(7): error C2059: syntax error: '>'
path\to\project\metatypes.h(7): error C2976: 'QMetaTypeId': too few template arguments
c:\qt\qt-everywhere-opensource-src-5.5.0\qtbase\include\qtcore\../../src/corelib/kernel/qmetatype.h(1576): note: see declaration of 'QMetaTypeId'
path\to\project\metatypes.h(7): error C2913: explicit specialization; 'QMetaTypeId' is not a specialization of a class template
..\..\ml_project\boost-libs\include\boost/multi_array.hpp(111): note: see declaration of 'boost::multi_array'
..\..\ml_project\boost-libs\include\boost/multi_array.hpp(111): note: see declaration of 'boost::multi_array'
path\to\project\metatypes.h(7): error C2226: syntax error: unexpected type 'quintptr'
path\to\project\metatypes.h(7): error C2143: syntax error: missing ')' before ';'
path\to\project\metatypes.h(7): error C2143: syntax error: missing ';' before '}'
like image 434
Alex Shtof Avatar asked Aug 31 '15 15:08

Alex Shtof


1 Answers

The comma between double, 2 is parsed as part of the macro definition. The solutions are as follows:

Option #1

typedef boost::multi_array<double, 2> my_name;

Q_DECLARE_METATYPE( my_name );

Option #2

#include <boost/utility/identity_type.hpp>

Q_DECLARE_METATYPE( BOOST_IDENTITY_TYPE( (boost::multi_array<double, 2>) ) );

Option #3

Hand-written BOOST_IDENTITY_TYPE:

template <typename T> struct identity_type;
template <typename T> struct identity_type<void(T)> { typedef T type; };

#define IDENTITY_TYPE(T) typename identity_type<void T>::type

Q_DECLARE_METATYPE( IDENTITY_TYPE( (boost::multi_array<double, 2>) ) );

Option #4

Replace a comma by a preprocessor macro:

#define COMMA ,
Q_DECLARE_METATYPE( boost::multi_array<double COMMA 2> );
#undef COMMA
like image 102
Piotr Skotnicki Avatar answered Sep 29 '22 23:09

Piotr Skotnicki