Anonymous arrays in C++ -


in c99+ can use anonymous arrays , structs compound literals, e.g.

void f(unsigned char *data);  f((char []){ 42, 15, 33 }); 

that equivalently

{     char tmp[] = { 42, 15, 33 };     f(tmp); } 

are there ways similar things in c++?

in c++11 have std::initializer_list allows similar:

// declare function void f(std::initializer_list<int> data);  ...  // call function f({ 1, 2, 3, 4 }); 

most containers have been modified take std::initializer_list, can have e.g. std::vector instead:

// function declaration, call before void f(const std::vector<int>& data); 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -