| Home | Libraries | People | FAQ | More

### Class `fiber`

    #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;
    };

##### Constructor

    fiber() noexcept;

Effects:

  Creates a invalid fiber.

Throws:

  Nothing.

##### Constructor

    template<typename Fn>
    fiber(Fn && fn);

    template<typename StackAlloc, typename Fn>
    fiber(std::allocator_arg_t, StackAlloc && salloc, Fn && fn);

Effects:

  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.

##### Destructor

    ~fiber();

Effects:

  Destructs the associated stack if `*this` is a valid fiber, e.g. fiber::operator bool() returns `true`.

Throws:

  Nothing.

##### Move constructor

    fiber(fiber && other) noexcept;

Effects:

  Moves underlying capture fiber to `*this`.

Throws:

  Nothing.

##### Move assignment operator

    fiber & operator=(fiber && other) noexcept;

Effects:

  Moves the state of `other` to `*this` using move semantics.

Throws:

  Nothing.

##### Member function `operator()`()

    fiber resume() &&;

    template<typename Fn>
    fiber resume_with(Fn && fn) &&;

Effects:

  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`).

Returns:

  The fiber representing the fiber that has been suspended.

Note:

  Because `*this` gets invalidated, `resume()` and `resume_with()` are rvalue-ref qualified and bind only to rvalues.

Note:

  Function `fn` needs to return `fiber`.

Note:

  The returned fiber indicates if the suspended fiber has terminated (return from context-function) via `bool operator()`.

##### Member function `operator bool`()

    explicit operator bool() const noexcept;

Returns:

  `true` if `*this` points to a captured fiber.

Throws:

  Nothing.

##### Member function `operator!`()

    bool operator!() const noexcept;

Returns:

  `true` if `*this` does not point to a captured fiber.

Throws:

  Nothing.

##### Member function `operator==`()

    bool operator==(fiber const& other) const noexcept;

Returns:

  `true` if `*this` and `other` represent the same fiber, `false` otherwise.

Throws:

  Nothing.

##### Member function `operator!=`()

    bool operator!=(fiber const& other) const noexcept;

Returns:

  `! (other == * this)`

Throws:

  Nothing.

##### Member function `operator<`()

    bool operator<(fiber const& other) const noexcept;

Returns:

  `true` if `*this != other` is true and the implementation-defined total order of `fiber` values places `*this` before `other`, false otherwise.

Throws:

  Nothing.

##### Member function `operator>`()

    bool operator>(fiber const& other) const noexcept;

Returns:

  `other < * this`

Throws:

  Nothing.

##### Member function `operator<=`()

    bool operator<=(fiber const& other) const noexcept;

Returns:

  `! (other < * this)`

Throws:

  Nothing.

##### Member function `operator>=`()

    bool operator>=(fiber const& other) const noexcept;

Returns:

  `! (* this < other)`

Throws:

  Nothing.

##### Non-member function `operator<<()`

    template<typename charT,class traitsT>
    std::basic_ostream<charT,traitsT> &
    operator<<(std::basic_ostream<charT,traitsT> & os,fiber const& other);

Effects:

  Writes the representation of `other` to stream `os`.

Returns:

  `os`