What do square brackets mean in this C++ statement? [duplicate] - c++

This question already has answers here:
What is a lambda expression in C++11?
(10 answers)
Strange bracket-parentheses notation in C++, looking somewhat like a for each loop
(3 answers)
What does "[ this ]" mean in C++
(1 answer)
Closed 2 years ago.
I'm going through Wt web framework tutorial, in one example they initialize a variable this way:
auto greet = [this]{
greeting_->setText("Hello there, " + nameEdit_->text());
};
What does square brackets mean in this type of initialization?

Related

What is the scope and evaluation of this if [duplicate]

This question already has answers here:
Declaring and initializing a variable in a Conditional or Control statement in C++
(9 answers)
Defining a variable in the condition part of an if-statement?
(5 answers)
Closed 1 year ago.
When cleaning up some code that I have found online, I came across with this weird c++ line:
if (int i = 1) std::cout << i;
With LLVM it compiled fine and the console output is 1, but how does the scope is handled in here, shouldn't the i variable be only accessible inside the conditional (inside the parenthesis)? And how is that possible to be evaluated to true, isn't an assignment a void operation and with no value, so 0/false? What is going on with this line?

How does int[int*] work in cpp? what is it's output? [duplicate]

This question already has answers here:
C++ array[index] vs index[array] [duplicate]
(4 answers)
is int[pointer-to-array] in the C++ - standard? [duplicate]
(3 answers)
Closed 2 years ago.
int a[5]={1,2,3,4,5};
int*p=a;
cout<<4[p];
return 0;
can anyone please tell me how it is giving output 5. i know it is 5 because it is the 4th element in the array. but why is 4[p] giving the output!

What is the meaning of sign + in front of a lambda? [duplicate]

This question already has answers here:
Resolving ambiguous overload on function pointer and std::function for a lambda using + (unary plus)
(1 answer)
A positive lambda: '+[]{}' - What sorcery is this? [duplicate]
(1 answer)
Closed 2 years ago.
int main()
{
void(*fp1)() = []{}; // ok
void(*fp2)() = +[]{}; // also ok
}
I cannot find any explanation in cppreference.com on the meaning of sign + in front of the lambda.
What is the exact meaning of sign + here as per the C++ standard?

square bracket and the pair type in C++ [duplicate]

This question already has answers here:
Understand structured binding in C++17 by analogy
(1 answer)
What are the new features in C++17?
(1 answer)
Structured binding and tie()
(2 answers)
Closed 4 years ago.
I read a piece of code from a book but I do not really understand the grammar,
const auto& [local_min, local_max] = minmax(A[i], A[i+1]);
where A is vector of int and local_min and local_max are int.
I know minmax returns a pair, but what does the square brackets do, i.e. [local_min, local_max]? I guess it is not for arrays here.
Thanks.

3d std::array in c++ [duplicate]

This question already has answers here:
C++11: Correct std::array initialization?
(5 answers)
Why can't simple initialize (with braces) 2D std::array? [duplicate]
(1 answer)
Closed 5 years ago.
I am early in c++. I want to define an 3d std::array in c++. when i define bellow array:
std::array<std::array<std::array<double,3>,4>, 4> DownSide = {
{{0,0.51,0.35},{0,0.51,0.35},{0,0.51,0.35},{0,0.51,0.35}},
{{0,0.51,0.35},{0,0.51,0.35},{0,0.51,0.35},{0,0.51,0.35}},
{{0,0.51,0.35},{0,0.51,0.35},{0,0.51,0.35},{0,0.51,0.35}},
{{0,0.51,0.35},{0,0.51,0.35},{0,0.51,0.35},{0,0.51,0.35}}
};
I see this error:
error: too many initializers for ‘std::array<std::array<std::array<double, 3ul>, 4ul>, 4ul>’
};
I googled this error find i mistak in numer brackets, but i dont know and find how must i write them.
How must i do?