Has anyone ever had a use for the __COUNTER__ pre-processor macro?

前端 未结 16 1572
有刺的猬
有刺的猬 2020-11-29 00:37

The __COUNTER__ symbol is provided by VC++ and GCC, and gives an increasing non-negative integral value each time it is used.

I\'m interested to learn w

16条回答
  •  忘掉有多难
    2020-11-29 00:56

    It is used by Boost.Asio to implement stackless coroutines.

    See this header file and examples.

    Resulting coroutines look like this:

    struct task : coroutine
    {
      ...
      void operator()()
      {
        reenter (this)
        {
          while (... not finished ...)
          {
             ... do something ...
             yield;
             ... do some more ...
             yield;
           }
         }
       }
       ...
    };
    

提交回复
热议问题