Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ meaning of [ ] [duplicate]

That's from an example of boosts asio. What does [this] mean? why the []?

acceptor_.async_accept(socket_,
    [this](boost::system::error_code ec)
like image 296
deW1 Avatar asked Mar 11 '14 13:03

deW1


People also ask

What is duplicate example?

always used before a noun. : exactly the same as something else. I began receiving duplicate copies of the magazine every month.

What is the meaning of duplicate data?

Duplicate data is any record that inadvertently shares data with another record in a Database. Duplicate data is easy to spot and it mostly occurs when transferring data between systems. The most popular occurrence of duplicate data is a complete carbon copy of a record.

What does duplicate work mean?

It's called duplicate work – literally redoing work that's already been done – and you can just imagine what it's doing to your productivity.


2 Answers

It is a lambda expression used to create a function as an expression

[] is the capture list

A list of symbols can be passed as follows:

  • [a,&b] where a is captured by value and b is captured by reference.
  • [this] captures the this pointer by value
  • [&] captures all automatic variables mentioned in the body of the lambda by reference
  • [=] captures all automatic variables mentioned in the body of the lambda by value
  • [] captures nothing
like image 84
Rahul Tripathi Avatar answered Oct 14 '22 15:10

Rahul Tripathi


It is a part of a lambda expression. Look here for more info.

like image 44
9er Avatar answered Oct 14 '22 15:10

9er