Using boost::future with “then” continuations

后端 未结 4 1569
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-24 12:35

The C++ 11 std::future lacks a then method to attach continuations to the future.

The Boost boost::future provides this, and t

4条回答
  •  余生分开走
    2020-12-24 13:14

    Boost.Thread comes in several versions of which you can choose via the BOOST_THREAD_VERSION macro. Currently, the default is 2.

    Up to version 2 of Boost.Thread, the name boost::unique_future was used for this class template (compare to boost::shared_future). Probably because of the standardization of std::future, more recent versions can use the name boost::future. Starting with version 3, boost::future is the default name.

    The selection which name is to be used is done via a preprocessor macro:

    When BOOST_THREAD_VERSION==2 define BOOST_THREAD_PROVIDES_FUTURE if you want to use boost::future. When BOOST_THREAD_VERSION>=3 define BOOST_THREAD_DONT_PROVIDE_FUTURE if you want to use boost::unique_future.

    From boost docs: unique_future vs future


    So you can either explicitly enable boost::future by using BOOST_THREAD_PROVIDES_FUTURE or switch to a more modern version of Boost.Thread by setting BOOST_THREAD_VERSION to 4, for example.

提交回复
热议问题