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 - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -