...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
#include <boost/context/fiber.hpp> class fiber { public: fiber() noexcept; template<typename Fn> fiber(Fn && fn); template<typename StackAlloc, typename Fn> fiber(std::allocator_arg_t, StackAlloc && salloc, Fn && fn); ~fiber(); fiber(fiber && other) noexcept; fiber & operator=(fiber && other) noexcept; fiber(fiber const& other) noexcept = delete; fiber & operator=(fiber const& other) noexcept = delete; fiber resume() &&; template<typename Fn> fiber resume_with(Fn && fn) &&; explicit operator bool() const noexcept; bool operator!() const noexcept; bool operator==(fiber const& other) const noexcept; bool operator!=(fiber const& other) const noexcept; bool operator<(fiber const& other) const noexcept; bool operator>(fiber const& other) const noexcept; bool operator<=(fiber const& other) const noexcept; bool operator>=(fiber const& other) const noexcept; template<typename charT,class traitsT> friend std::basic_ostream<charT,traitsT> & operator<<(std::basic_ostream<charT,traitsT> & os,fiber const& other) { void swap(fiber & other) noexcept; };
fiber() noexcept;
Creates a invalid fiber.
Nothing.
template<typename Fn> fiber(Fn && fn); template<typename StackAlloc, typename Fn> fiber(std::allocator_arg_t, StackAlloc && salloc, Fn && fn);
Creates a new fiber and prepares the context to execute fn
. fixedsize_stack
is used as default stack allocator (stack size == fixedsize_stack::traits::default_size()).
The constructor with argument type preallocated
,
is used to create a user defined data (for
instance additional control structures) on top of the stack.
~fiber();
Destructs the associated stack if *this
is a valid fiber, e.g. fiber::operator
bool() returns true
.
Nothing.
fiber(fiber && other) noexcept;
Moves underlying capture fiber to *this
.
Nothing.
fiber & operator=(fiber && other) noexcept;
Moves the state of other
to *this
using move semantics.
Nothing.
operator()
()
fiber resume() &&; template<typename Fn> fiber resume_with(Fn && fn) &&;
Captures current fiber and resumes *this
. The function resume_with
,
is used to execute function fn
in the execution context of *this
(e.g. the stack frame of fn
is allocated on stack of *this
).
The fiber representing the fiber that has been suspended.
Because *this
gets invalidated, resume()
and resume_with()
are rvalue-ref qualified and bind
only to rvalues.
Function fn
needs to
return fiber
.
The returned fiber indicates if the suspended fiber has terminated
(return from context-function) via bool
operator()
.
operator bool
()
explicit operator bool() const noexcept;
true
if *this
points to a captured fiber.
Nothing.
operator!
()
bool operator!() const noexcept;
true
if *this
does not point to a captured fiber.
Nothing.
operator==
()
bool operator==(fiber const& other) const noexcept;
true
if *this
and other
represent
the same fiber, false
otherwise.
Nothing.
operator!=
()
bool operator!=(fiber const& other) const noexcept;
! (other == * this)
Nothing.
operator<
()
bool operator<(fiber const& other) const noexcept;
true
if *this != other
is true and the implementation-defined total order of fiber
values places *this
before other
, false
otherwise.
Nothing.
operator>
()
bool operator>(fiber const& other) const noexcept;
other <
* this
Nothing.
operator<=
()
bool operator<=(fiber const& other) const noexcept;
! (other <
* this)
Nothing.
operator>=
()
bool operator>=(fiber const& other) const noexcept;
! (*
this <
other)
Nothing.
operator<<()
template<typename charT,class traitsT> std::basic_ostream<charT,traitsT> & operator<<(std::basic_ostream<charT,traitsT> & os,fiber const& other);
Writes the representation of other
to stream os
.
os