I just started C++, how can I print only rows of 2d vector?
This is how I'm trying to do it but it fails.
std::vector<std::vector<int>> matrix2d{{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12}};
for (std::vector<int> i : matrix2d) {
std::cout << i << std::endl;
}
I get an error under std::cout <<.
Error nvalid operands to binary expression ('std::ostream' (aka 'basic_ostream<char>') and 'const std::vector<double>') candidate template ignored: deduced conflicting types for parameter '_CharT' ('char' vs. 'std::vector<double, std::allocator<double> >') candidate template ignored: could not match 'basic_string' against 'vector' candidate template ignored: could not match 'const _CharT *' against 'std::vector<double>' candidate template ignored: requirement '__and_<std::__not_<std::is_lvalue_reference<std::basic_ostream<char, std::char_traits<char> > &> >, std::__is_convertible_to_basic_ostream<std::basic_ostream<char, std::char_traits<char> > &>, st...
Related
Why does the following code compile when using std::array but not when using std::vector:
using varianttypes = std::variant<int, double, std::unique_ptr<double>>;
std::array<varianttypes, 4> a{1, 2.2, 3, 4.3}; // compiles fine
std::vector<varianttypes> a{1, 2.2, 3, 4.3}; // gives an error
I get this error:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/allocator_traits.h:298:9: error: no matching function for call to 'construct_at'
_VSTD::construct_at(__p, _VSTD::forward<_Args>(__args)...);
^~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__config:858:15: note: expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_ABI_NAMESPACE
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/memory:750:18: note: in instantiation of function template specialization 'std::allocator_traits<std::allocator<std::variant<int, double, std::unique_ptr<double>>>>::construct<std::variant<int, double, std::unique_ptr<double>>, const std::variant<int, double, std::unique_ptr<double>> &, void, void>' requested here
_Traits::construct(__a, _VSTD::__to_address(__begin2), *__begin1);
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/vector:1099:12: note: in instantiation of function template specialization 'std::__construct_range_forward<std::allocator<std::variant<int, double, std::unique_ptr<double>>>, const std::variant<int, double, std::unique_ptr<double>> *, std::variant<int, double, std::unique_ptr<double>> *>' requested here
_VSTD::__construct_range_forward(this->__alloc(), __first, __last, __tx.__pos_);
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/vector:1357:9: note: in instantiation of function template specialization 'std::vector<std::variant<int, double, std::unique_ptr<double>>>::__construct_at_end<const std::variant<int, double, std::unique_ptr<double>> *>' requested here
__construct_at_end(__il.begin(), __il.end(), __il.size());
^
variantstuff.cpp:82:29: note: in instantiation of member function 'std::vector<std::variant<int, double, std::unique_ptr<double>>>::vector' requested here
std::vector<varianttypes> a{1, 2.2, 3, 4.3};
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/construct_at.h:35:16: note: candidate template ignored: substitution failure [with _Tp = std::variant<int, double, std::unique_ptr<double>>, _Args = <const std::variant<int, double, std::unique_ptr<double>> &>]: call to implicitly-deleted copy constructor of 'std::variant<int, double, std::unique_ptr<double>>'
constexpr _Tp* construct_at(_Tp* __location, _Args&& ...__args) {
^
1 error generated.
make: *** [variantstuff.o] Error 1
This question already has answers here:
Can std::begin work with array parameters and if so, how?
(5 answers)
Closed 1 year ago.
I have some simple code
#include<iterator>
int main() {
int y[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
auto a = std::begin(y);
std::cout << *a << std::endl;
return 0;
}
Which prints out 1 as expected.
However if I do this :
void checkNested(int val [10]) {
auto a = std::begin(val);
std::cout << *a << std::endl;
}
int main() {
int y[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
checkNested(y);
return 0;
}
I get compilation failures from both clang++ and g++.
From clang++ specifically I get:
auto a = std::begin(input);
^~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/initializer_list:89:5: note: candidate template ignored: could not match 'initializer_list<type-parameter-0-0>' against 'int *'
begin(initializer_list<_Tp> __ils) noexcept
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/range_access.h:48:5: note: candidate template ignored: substitution failure [with _Container = int *]: member reference base type 'int *' is not a structure or union
begin(_Container& __cont) -> decltype(__cont.begin())
^ ~
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/range_access.h:58:5: note: candidate template ignored: substitution failure [with _Container = int *]: member reference base type 'int *const' is not a structure or union
begin(const _Container& __cont) -> decltype(__cont.begin())
^ ~
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/range_access.h:87:5: note: candidate template ignored: could not match '_Tp [_Nm]' against 'int *'
begin(_Tp (&__arr)[_Nm])
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/range_access.h:104:31: note: candidate template ignored: could not match 'valarray<type-parameter-0-0>' against 'int *'
template<typename _Tp> _Tp* begin(valarray<_Tp>&);
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/range_access.h:105:37: note: candidate template ignored: could not match 'valarray<type-parameter-0-0>' against 'int *'
template<typename _Tp> const _Tp* begin(const valarray<_Tp>&);
Just wanna know if there's something really obvious I'm missing here since I expected them to function the same.
Thanks
An array can't be passed by value, so your array decays into a pointer when passed to checkNested(), and std::begin() is not defined for a pointer, hence the error.
void checkNested(int val [10]) is just syntax sugar for void checkNested(int *val).
If you pass the array by reference instead, then the code will work:
void checkNested(int (&val) [10])
My code use templates heavily. I have a number of overloaded functions
auto operator>>(byte_vector_view&bvv, Type&&) ->byte_vector_view&;
This works fine until unknown by this function family type is passed to function:
bvv >> my_custom;
User should simply see one error message:
There no implementation for operator>>(byte_vector_view&bvv, my_custom_type&)
instead we see a very long manuscript:
how to put this under spoiler?
itm.cpp:184:18: error: invalid operands to binary expression ('byte_vector_view' and 'named_value<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > >')
((bvv>>elements),...);
~~~^ ~~~~~~~~
/Library/Developer/CommandLineTools/usr/include/c++/v1/type_traits:4345:23: note: in instantiation of function template specialization 'operator>>(byte_vector_view &, std::__1::tuple<named_value<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > > > &)::(anonymous class)::operator()<named_value<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > > >' requested here
_LIBCPP_INVOKE_RETURN(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...))
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/__config:508:15: note: expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_NAMESPACE
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/tuple:1375:5: note: while substituting deduced template arguments into function template '__invoke_constexpr' [with _Fp = (lambda at itm.cpp:183:9), _Args = <named_value<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > > &>]
_VSTD::__invoke_constexpr(
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/__config:508:15: note: expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_NAMESPACE
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/tuple:1372:26: note: in instantiation of exception specification for '__apply_tuple_impl<(lambda at itm.cpp:183:9), std::__1::tuple<named_value<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > > > &, 0>' requested here
constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/tuple:1384:12: note: in instantiation of function template specialization 'std::__1::__apply_tuple_impl<(lambda at itm.cpp:183:9), std::__1::tuple<named_value<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > > > &, 0>' requested here
_VSTD::__apply_tuple_impl(
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/tuple:1382:26: note: in instantiation of exception specification for 'apply<(lambda at itm.cpp:183:9), std::__1::tuple<named_value<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > > > &>' requested here
constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
^
itm.cpp:182:5: note: in instantiation of function template specialization 'std::__1::apply<(lambda at itm.cpp:183:9), std::__1::tuple<named_value<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > > > &>' requested here
apply(
^
itm.cpp:461:20: note: in instantiation of function template specialization 'operator>><std::__1::tuple<named_value<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > > > >' requested here
bvv>>tvs;
^
itm.cpp:427:12: note: in instantiation of member function 'make_converter(bool, std::__1::tuple<named_value<ringnet::proto::opcode>, named_value<command_address> > &&, named_value<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > > &&)::Ret::from_byte_vector_view' requested here
struct Ret:converter_virtual{
^
itm.cpp:537:12: note: in instantiation of function template specialization 'make_converter<std::__1::tuple<named_value<ringnet::proto::opcode>, named_value<command_address> >, named_value<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > > >' requested here
return make_converter(false,forward<Prefix>(prefix),forward<Ts>(values)...);
^
itm.cpp:931:18: note: in instantiation of function template specialization 'make_converter<std::__1::tuple<named_value<ringnet::proto::opcode>, named_value<command_address> >, named_value<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > > >' requested here
/*response*/make_converter(
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/type_traits:4840:3: note: candidate function template not viable: no known conversion from 'byte_vector_view' to 'std::byte' for 1st argument
operator>> (byte __lhs, _Integer __shift) noexcept
^
itm.cpp:147:19: note: candidate function not viable: no known conversion from 'named_value<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > >' to 'uint8_t &' (aka 'unsigned char &') for 2nd argument
byte_vector_view& operator>>(byte_vector_view&bvv, uint8_t&ui8){
^
itm.cpp:151:19: note: candidate function not viable: no known conversion from 'named_value<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > >' to 'std::__1::string &' (aka 'basic_string<char, char_traits<char>, allocator<char> > &') for 2nd argument
byte_vector_view& operator>>(byte_vector_view&bvv, string&str){
^
itm.cpp:156:19: note: candidate function not viable: no known conversion from 'named_value<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > >' to 'named_value<std::__1::string> &' (aka 'named_value<basic_string<char, char_traits<char>, allocator<char> > > &') for 2nd argument
byte_vector_view& operator>>(byte_vector_view&bvv, named_value<string>&av){
^
itm.cpp:161:6: note: candidate template ignored: requirement 'is_integral_v<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > > || is_same_v<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >, ringnet::proto::opcode> || is_same_v<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >, command_address>' was not satisfied [with T = std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >]
auto operator>>(byte_vector_view&bvv, named_value<T>&av) ->enable_if_t<is_integral_v<T> || is_same_v<T,opcode> || is_same_v<T,command_address>, byte_vector_view&>{
^
itm.cpp:181:6: note: candidate template ignored: requirement 'is_tuple<named_value<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > > >' was not satisfied [with TupleT = named_value<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > >]
auto operator>>(byte_vector_view&bvv, TupleT&tu) ->enable_if_t<is_tuple<TupleT>,byte_vector_view&> {
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/istream:521:1: note: candidate template ignored: could not match 'basic_istream<type-parameter-0-0, type-parameter-0-1>' against 'byte_vector_view'
operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s)
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/istream:570:1: note: candidate template ignored: could not match 'basic_istream<char, type-parameter-0-0>' against 'byte_vector_view'
operator>>(basic_istream<char, _Traits>& __is, unsigned char* __s)
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/istream:578:1: note: candidate template ignored: could not match 'basic_istream<char, type-parameter-0-0>' against 'byte_vector_view'
operator>>(basic_istream<char, _Traits>& __is, signed char* __s)
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/istream:585:1: note: candidate template ignored: could not match 'basic_istream<type-parameter-0-0, type-parameter-0-1>' against 'byte_vector_view'
operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c)
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/istream:613:1: note: candidate template ignored: could not match 'basic_istream<char, type-parameter-0-0>' against 'byte_vector_view'
operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c)
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/istream:621:1: note: candidate template ignored: could not match 'basic_istream<char, type-parameter-0-0>' against 'byte_vector_view'
operator>>(basic_istream<char, _Traits>& __is, signed char& __c)
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/istream:1219:1: note: candidate template ignored: could not match 'basic_istream<type-parameter-0-0, type-parameter-0-1>' against 'byte_vector_view'
operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp&& __x)
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/istream:1287:1: note: candidate template ignored: could not match 'basic_istream<type-parameter-0-0, type-parameter-0-1>' against 'byte_vector_view'
operator>>(basic_istream<_CharT, _Traits>& __is,
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/istream:1419:1: note: candidate template ignored: could not match 'basic_istream<type-parameter-0-0, type-parameter-0-1>' against 'byte_vector_view'
operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/iomanip:302:1: note: candidate template ignored: could not match 'basic_istream<type-parameter-0-0, type-parameter-0-1>' against 'byte_vector_view'
operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_MoneyT>& __x)
It's hard to read and understand where is the problem exactly and therefore hard to fix the problem
Need more clear explanation
I found one straightforward way to suppress excess output:
template<typename UnknownType>
auto operator>>(byte_vector_view&bvv, UnknownType&&) ->byte_vector_view& {
static_assert(false);
return bvv;
}
With it compiler gives a quiet short error message, too short:
itm.cpp:192:5: error: static_assert failed
static_assert(false);
^ ~~~~~
1 error generated.
I'd like to see in which function the error appeared and a trace how compiler come there:
template<typename UnknownType>
auto operator>>(byte_vector_view&bvv, UnknownType&&) ->byte_vector_view& {
static_assert(false&&__PRETTY_FUNCTION__);
return bvv;
}
itm.cpp:192:5: error: static_assert failed
static_assert(false && __PRETTY_FUNCTION__);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
itm.cpp:184:18: note: in instantiation of function template specialization 'operator>><named_value<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > > &>' requested here
((bvv>>elements),...);
^
itm.cpp:461:20: note: in instantiation of function template specialization 'operator>><std::__1::tuple<named_value<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > > > >' requested here
bvv>>tvs;
^
itm.cpp:427:12: note: in instantiation of member function 'make_converter(bool, std::__1::tuple<named_value<ringnet::proto::opcode>, named_value<command_address> > &&, named_value<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > > &&)::Ret::from_byte_vector_view' requested here
struct Ret:converter_virtual{
^
itm.cpp:537:12: note: in instantiation of function template specialization 'make_converter<std::__1::tuple<named_value<ringnet::proto::opcode>, named_value<command_address> >, named_value<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > > >' requested here
return make_converter(false,forward<Prefix>(prefix),forward<Ts>(values)...);
^
itm.cpp:931:18: note: in instantiation of function template specialization 'make_converter<std::__1::tuple<named_value<ringnet::proto::opcode>, named_value<command_address> >, named_value<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > > >' requested here
/*response*/make_converter(
^
1 error generated.
And this is almost looks like I want but Clang++ does not expand __PRETTY_FUNCTION__ in static_assert.
Is there a way to put expanded UnknownType to static_assert's message?
I also tried
static_assert(false,__PRETTY_FUNCTION__);
but it gives
error: expected string literal for diagnostic message in static_assert
#include <type_traits>
template <typename UnknownType>
struct Type_Not_Supported : std::false_type {};
template <typename UnknownType>
auto operator>>(byte_vector_view& bvv, UnknownType&&) -> byte_vector_view& {
static_assert(Type_Not_Supported<UnknownType>{});
return bvv;
}
In Clang, this yields:
prog.cc:10:5: error: static_assert failed due to requirement 'Type_Not_Supported<int>{}'
static_assert(Type_Not_Supported<UnknownType>{});
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.cc:17:9: note: in instantiation of function template specialization 'operator>><int>' requested here
bvv >> 1;
^
1 error generated.
In GCC:
prog.cc: In instantiation of 'byte_vector_view& operator>>(byte_vector_view&, UnknownType&&) [with UnknownType = int]':
prog.cc:17:12: required from here
prog.cc:10:19: error: static assertion failed
10 | static_assert(Type_Not_Supported<UnknownType>{});
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DEMO
This question already has an answer here:
no matching function for call to ‘regex_search(...)'
(1 answer)
Closed 3 years ago.
My code should do this:
input: (x+y) => (x*y)
output: (x+y)
regexp works well I tested them on a website regexp101.com
If I remove the match parameter from regexp_match() code works.
But it does not return the regexp result.
I get this error when I run this command:
> g++ -std=c++11 main.cpp
ERROR
main.cpp:14:9: error: no matching function for call to 'regex_match'
if (regex_match(formula,match, firstBrace)){
^~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:6038:1: note:
candidate template ignored: deduced conflicting types for parameter '_BidirectionalIterator'
('std::__1::basic_string<char>' vs. 'std::__1::match_results<const char *,
std::__1::allocator<std::__1::sub_match<const char *> > >')
regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:6049:1: note:
candidate template ignored: could not match 'const _CharT *' against 'std::__1::string' (aka
'basic_string<char, char_traits<char>, allocator<char> >')
regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:6059:1: note:
candidate template ignored: deduced type 'match_results<typename basic_string<char,
char_traits<char>, allocator<char> >::const_iterator, [...]>' of 2nd parameter does not match
adjusted type 'match_results<const char *, [...]>' of argument [with _ST =
std::__1::char_traits<char>, _SA = std::__1::allocator<char>, _Allocator =
std::__1::allocator<std::__1::sub_match<const char *> >, _CharT = char, _Traits =
std::__1::regex_traits<char>]
regex_match(const basic_string<_CharT, _ST, _SA>& __s,
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:6080:1: note:
candidate template ignored: could not match 'const _CharT *' against 'std::__1::string' (aka
'basic_string<char, char_traits<char>, allocator<char> >')
regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:6089:1: note:
candidate template ignored: could not match 'basic_regex' against 'match_results'
regex_match(const basic_string<_CharT, _ST, _SA>& __s,
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:5366:5: note:
candidate function template not viable: requires at least 4 arguments, but 3 were provided
regex_match(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&,
^
1 error generated.
#include <iostream>
#include <string>
#include <regex>
using namespace std;
int main() {
string formula;
cout << "Write down a formula" << endl;
cin >> formula;
cmatch match;
regex firstBrace("(\\()(\\w\\+)+(.\\))\\s?");
if (regex_match(formula,match, firstBrace)){
cout << "String 'a' matches regular expression 'b' \n";
cmatch mcopy (match); // copy constructor
for (unsigned i=0; i<mcopy.size(); ++i)
cout << "match " << i << ": " << mcopy[i] << endl;
}
return 0;
}
How can I get the result from regexp?
Your current code doesn't compile because type of target doesn't match to type of match results. If you pass string as input, matched results will be stored in smatch. When input is const char*, results are stored in cmatch.
You have to replace cmatch occurences by smatch.
I want to use "reshape()" fuction in Eigen unsupported tensor, but my source code cannot be compiled.
The compilation was done as follows.
g++ -std=c++14 -I (path to Eigen) eigen_practice.cpp -o eigen_practice
and here is my source code.
# include "unsupported/Eigen/CXX11/Tensor"
using namespace Eigen;
int main(){
Tensor<float, 2> input(7, 11);
Eigen::array<int, 3> three_dims{{7, 11, 1}};
Tensor<float, 3> result = input.reshape(three_dims);
return 0;
}
And here is the error messeage.
In file included from eigen_practice.cpp:12:
In file included from /Users/yamamototatsuto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/Tensor:145:
/Users/yamamototatsuto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/src/Tensor/Tensor.h:397:7: error:
no matching member function for call to 'resize'
resize(TensorEvaluator<const Assign, DefaultDevice>(assign, Defaul...
^~~~~~
eigen_practice.cpp:63:28: note: in instantiation of function template
specialization 'Eigen::Tensor<float, 3, 0,
long>::Tensor<Eigen::TensorReshapingOp<const std::__1::array<int, 3>,
Eigen::Tensor<float, 2, 0, long> > >' requested here
Tensor<float, 3> result = input.reshape(three_dims);
^
/Users/yamamototatsuto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/src/Tensor/Tensor.h:423:10: note:
candidate function template not viable: no known conversion from 'const
Eigen::TensorEvaluator<const Eigen::TensorAssignOp<Eigen::Tensor<float, 3,
0, long>, const Eigen::TensorReshapingOp<const std::__1::array<int, 3>,
Eigen::Tensor<float, 2, 0, long> > >, Eigen::DefaultDevice>::Dimensions'
(aka 'const std::__1::array<int, 3>') to 'Eigen::Tensor<float, 3, 0,
long>::Index' (aka 'long') for 1st argument
void resize(Index firstDimension, IndexTypes... otherDimensions)
^
/Users/yamamototatsuto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/src/Tensor/Tensor.h:432:28: note:
candidate function not viable: no known conversion from
'array<int, [...]>' to 'const array<long, [...]>' for 1st argument
EIGEN_DEVICE_FUNC void resize(const array<Index, NumIndices>& dimensions)
^
/Users/yamamototatsuto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/src/Tensor/Tensor.h:450:28: note:
candidate function not viable: no known conversion from 'const
Eigen::TensorEvaluator<const Eigen::TensorAssignOp<Eigen::Tensor<float, 3,
0, long>, const Eigen::TensorReshapingOp<const std::__1::array<int, 3>,
Eigen::Tensor<float, 2, 0, long> > >, Eigen::DefaultDevice>::Dimensions'
(aka 'const std::__1::array<int, 3>') to 'const
DSizes<Eigen::Tensor<float, 3, 0, long>::Index, NumIndices>' (aka 'const
DSizes<long, NumIndices>') for 1st argument
EIGEN_DEVICE_FUNC void resize(const DSizes<Index, NumIndices>& dimensions) {
^
/Users/yamamototatsuto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/src/Tensor/Tensor.h:479:10: note:
candidate template ignored: could not match 'Sizes' against 'array'
void resize(const Sizes<Indices...>& dimensions) {
^
/Users/yamamototatsuto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/src/Tensor/Tensor.h:459:10: note:
candidate function not viable: requires 0 arguments, but 1 was provided
void resize()
^
1 error generated.
This source code is just a copy of what is in the documentation.
(https://eigen.tuxfamily.org/dox/unsupported/eigen_tensors.html)
So it should compile, but it doesn't.
How can I solve it?
And why the error message mentions about "resize()" function?