7

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

acceptor_.async_accept(socket_,
    [this](boost::system::error_code ec)
deW1
  • 5,364
  • 10
  • 40
  • 53

2 Answers2

6

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
erodriguez
  • 3
  • 1
  • 3
Rahul Tripathi
  • 161,154
  • 30
  • 262
  • 319
4

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

9er
  • 1,434
  • 2
  • 15
  • 36