Собственная карта из 2d массива - PullRequest
0 голосов
/ 10 июня 2018

Почему это работает

typedef Matrix<double, N, N, RowMajor> Mat;
cout << Map<Mat>(&m[0][0]) << endl;

, но это не

cout << Map<Matrix<double, N, N, RowMajor>>(&m[0][0]) << endl;

Возможно ли сделать все это в одной строке?

ошибка была:

eigen_playground.cpp:16:46: warning: use of right-shift operator ('>>') in template argument will require parentheses in
      C++11 [-Wc++11-compat]
    cout << Map<Matrix<double, N, N, RowMajor>>(&m[0][0]) << endl;
                                             ^
                                     (                   )
eigen_playground.cpp:16:46: error: invalid operands to binary expression ('int' and 'double *')
    cout << Map<Matrix<double, N, N, RowMajor>>(&m[0][0]) << endl;
                                     ~~~~~~~~^ ~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:740:1: note: 
      candidate template ignored: could not match 'basic_istream<type-parameter-0-0, type-parameter-0-1>' against
      'Eigen::StorageOptions'
operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:789:1: note: 
      candidate template ignored: could not match 'basic_istream<char, type-parameter-0-0>' against 'Eigen::StorageOptions'
operator>>(basic_istream<char, _Traits>& __is, unsigned char* __s)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:797:1: note: 
      candidate template ignored: could not match 'basic_istream<char, type-parameter-0-0>' against 'Eigen::StorageOptions'
operator>>(basic_istream<char, _Traits>& __is, signed char* __s)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:804:1: note: 
      candidate template ignored: could not match 'basic_istream<type-parameter-0-0, type-parameter-0-1>' against
      'Eigen::StorageOptions'
operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:832:1: note: 
      candidate template ignored: could not match 'basic_istream<char, type-parameter-0-0>' against 'Eigen::StorageOptions'
operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:840:1: note: 
      candidate template ignored: could not match 'basic_istream<char, type-parameter-0-0>' against 'Eigen::StorageOptions'
operator>>(basic_istream<char, _Traits>& __is, signed char& __c)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:1506:1: note: 
      candidate template ignored: could not match 'basic_istream<type-parameter-0-0, type-parameter-0-1>' against
      'Eigen::StorageOptions'
operator>>(basic_istream<_CharT, _Traits>& __is,
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:1638:1: note: 
      candidate template ignored: could not match 'basic_istream<type-parameter-0-0, type-parameter-0-1>' against
      'Eigen::StorageOptions'
operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/complex:1369:1: note: 
      candidate template ignored: could not match 'basic_istream<type-parameter-0-1, type-parameter-0-2>' against
      'Eigen::StorageOptions'
operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x)
^
eigen_playground.cpp:16:66: error: expected a type
    cout << Map<Matrix<double, N, N, RowMajor>>(&m[0][0]) << endl;
                                                                 ^
1 warning and 2 errors generated.

1 Ответ

0 голосов
/ 10 июня 2018

Причина, по которой вы получаете ошибку, состоит в том, что до C ++ 11 два соседних символа ">>" агрессивно интерпретируются как оператор смещения вправо .

, так каквы используете стандарт C ++ раньше, чем C ++ 11, просто добавьте пробел между этими двумя символами.

cout << Map< Matrix<double, N, N, RowMajor> >(&m[0][0]) << endl;
//                             right here. ^
...