c++ - Brace Enclosed Initializer List? convert to vector -


so have piece of code attempting test. code checking few vectors (these elements of structs) equivalent known vectors @ points, running issue. when attempt compare vector known vector follows,

assert((class1.getattr().getattr().getvec(key) == {4,3,2,2})) 

i following error:

assertall.cpp:105:82: error: not convert ‘{4,3,2,2}’ ‘<brace-enclosed initializer list>’ ‘std::vector<int>’ 

the rest of code correct, , lval of assert vector should be. compiling flags, -std=c++11 -wall -wextra -pedantic -o in g++. know how fix this? there way typecast bracket enclosed initializer list vector, or there better way this?

does know how fix this? there way typecast bracket enclosed initializer list vector

interestingly, different error on clang 3.5 , gcc 4.9.2 when try similar, can use initializer list syntax construct vector in place (not quite typecasting, guess):

assert((class1.getattr().getattr().getvec(key) == std::vector<int>{4,3,2,2})) 

i'm not sure how thing can run code on coliru , such, following code works me on gcc 4.9.2 using g++ -std=c++11 -wall -pedantic

#include <cassert> #include <vector>  std::vector<int> foo() {     return {1,2,3,4}; }  template<class t> bool is_equal(const t& a, const t& b) {     return == b; }  int main() {     assert((foo() == std::vector<int>{1,2,3,4}));      assert(is_equal(foo(), {1,2,3,4}));      assert([&](std::vector<int> v) -> bool {         return foo() == v;     }({1,2,3,4})); } 

granted, nobody in right mind use lambda that, might able tell examples, need tell compiler 2 sides same type in order convert initializer list vector.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -