14 Basic I/O services [io_context]

14.3 Class io_context::executor_type [io_context.exec]

namespace std {
namespace experimental {
namespace net {
inline namespace v1 {

  class io_context::executor_type
  {
  public:
    // [io_context.exec.cons], construct / copy / destroy:

    executor_type(const executor_type& other) noexcept;
    executor_type(executor_type&& other) noexcept;

    executor_type& operator=(const executor_type& other) noexcept;
    executor_type& operator=(executor_type&& other) noexcept;

    // [io_context.exec.ops], executor operations:

    bool running_in_this_thread() const noexcept;

    io_context& context() const noexcept;

    void on_work_started() const noexcept;
    void on_work_finished() const noexcept;

    template<class Func, class ProtoAllocator>
      void dispatch(Func&& f, const ProtoAllocator& a) const;
    template<class Func, class ProtoAllocator>
      void post(Func&& f, const ProtoAllocator& a) const;
    template<class Func, class ProtoAllocator>
      void defer(Func&& f, const ProtoAllocator& a) const;
  };

  bool operator==(const io_context::executor_type& a,
                  const io_context::executor_type& b) noexcept;
  bool operator!=(const io_context::executor_type& a,
                  const io_context::executor_type& b) noexcept;

} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std

io_context::executor_type is a type satisfying the Executor requirements ([async.reqmts.executor]). Objects of type io_context::executor_type are associated with an io_context, and function objects submitted using the dispatch, post, or defer member functions will be executed by the io_context from within a run function.]

14.3.1 io_context::executor_type constructors [io_context.exec.cons]

executor_type(const executor_type& other) noexcept;

Postconditions: *this == other.

executor_type(executor_type&& other) noexcept;

Postconditions: *this is equal to the prior value of other.

14.3.2 io_context::executor_type assignment [io_context.exec.assign]

executor_type& operator=(const executor_type& other) noexcept;

Postconditions: *this == other.

Returns: *this.

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

Postconditions: *this is equal to the prior value of other.

Returns: *this.

14.3.3 io_context::executor_type operations [io_context.exec.ops]

bool running_in_this_thread() const noexcept;

Returns: true if the current thread of execution is calling a run function of the associated io_context object. [ Note: That is, the current thread of execution's call chain includes a run function.  — end note ]

io_context& context() const noexcept;

Returns: A reference to the associated io_context object.

void on_work_started() const noexcept;

Effects: Increments the count of outstanding work associated with the io_context.

void on_work_finished() const noexcept;

Effects: Decrements the count of outstanding work associated with the io_context.

template<class Func, class ProtoAllocator> void dispatch(Func&& f, const ProtoAllocator& a) const;

Effects: If running_in_this_thread() is true, calls DECAY_COPY(forward<Func>(f))() (C++ 2014 [thread.decaycopy]). [ Note: If f exits via an exception, the exception propagates to the caller of dispatch().  — end note ] Otherwise, calls post(forward<Func>(f), a).

template<class Func, class ProtoAllocator> void post(Func&& f, const ProtoAllocator& a) const;

Effects: Adds f to the io_context.

template<class Func, class ProtoAllocator> void defer(Func&& f, const ProtoAllocator& a) const;

Effects: Adds f to the io_context.

14.3.4 io_context::executor_type comparisons [io_context.exec.comparisons]

bool operator==(const io_context::executor_type& a, const io_context::executor_type& b) noexcept;

Returns: addressof(a.context()) == addressof(b.context()).

bool operator!=(const io_context::executor_type& a, const io_context::executor_type& b) noexcept;

Returns: !(a == b).