Skip to content

Commit

Permalink
Add converting move construction/assignment to pipes.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskohlhoff committed Jun 30, 2022
1 parent 67bdae5 commit 8606891
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
47 changes: 47 additions & 0 deletions asio/include/asio/basic_readable_pipe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,53 @@ class basic_readable_pipe
impl_ = std::move(other.impl_);
return *this;
}

// All pipes have access to each other's implementations.
template <typename Executor1>
friend class basic_readable_pipe;

/// Move-construct a basic_readable_pipe from a pipe of another executor type.
/**
* This constructor moves a pipe from one object to another.
*
* @param other The other basic_readable_pipe object from which the move will
* occur.
*
* @note Following the move, the moved-from object is in the same state as if
* constructed using the @c basic_readable_pipe(const executor_type&)
* constructor.
*/
template <typename Executor1>
basic_readable_pipe(basic_readable_pipe<Executor1>&& other,
typename constraint<
is_convertible<Executor1, Executor>::value,
defaulted_constraint
>::type = defaulted_constraint())
: impl_(std::move(other.impl_))
{
}

/// Move-assign a basic_readable_pipe from a pipe of another executor type.
/**
* This assignment operator moves a pipe from one object to another.
*
* @param other The other basic_readable_pipe object from which the move will
* occur.
*
* @note Following the move, the moved-from object is in the same state as if
* constructed using the @c basic_readable_pipe(const executor_type&)
* constructor.
*/
template <typename Executor1>
typename constraint<
is_convertible<Executor1, Executor>::value,
basic_readable_pipe&
>::type operator=(basic_readable_pipe<Executor1>&& other)
{
basic_readable_pipe tmp(std::move(other));
impl_ = std::move(tmp.impl_);
return *this;
}
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)

/// Destroys the pipe.
Expand Down
47 changes: 47 additions & 0 deletions asio/include/asio/basic_writable_pipe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,53 @@ class basic_writable_pipe
impl_ = std::move(other.impl_);
return *this;
}

// All pipes have access to each other's implementations.
template <typename Executor1>
friend class basic_writable_pipe;

/// Move-construct a basic_writable_pipe from a pipe of another executor type.
/**
* This constructor moves a pipe from one object to another.
*
* @param other The other basic_writable_pipe object from which the move will
* occur.
*
* @note Following the move, the moved-from object is in the same state as if
* constructed using the @c basic_writable_pipe(const executor_type&)
* constructor.
*/
template <typename Executor1>
basic_writable_pipe(basic_writable_pipe<Executor1>&& other,
typename constraint<
is_convertible<Executor1, Executor>::value,
defaulted_constraint
>::type = defaulted_constraint())
: impl_(std::move(other.impl_))
{
}

/// Move-assign a basic_writable_pipe from a pipe of another executor type.
/**
* This assignment operator moves a pipe from one object to another.
*
* @param other The other basic_writable_pipe object from which the move will
* occur.
*
* @note Following the move, the moved-from object is in the same state as if
* constructed using the @c basic_writable_pipe(const executor_type&)
* constructor.
*/
template <typename Executor1>
typename constraint<
is_convertible<Executor1, Executor>::value,
basic_writable_pipe&
>::type operator=(basic_writable_pipe<Executor1>&& other)
{
basic_writable_pipe tmp(std::move(other));
impl_ = std::move(tmp.impl_);
return *this;
}
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)

/// Destroys the pipe.
Expand Down
4 changes: 4 additions & 0 deletions asio/src/tests/unit/readable_pipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,17 @@ void test()

#if defined(ASIO_HAS_MOVE)
readable_pipe pipe5(std::move(pipe4));

basic_readable_pipe<io_context::executor_type> pipe6(ioc);
readable_pipe pipe7(std::move(pipe6));
#endif // defined(ASIO_HAS_MOVE)

// basic_readable_pipe operators.

#if defined(ASIO_HAS_MOVE)
pipe1 = readable_pipe(ioc);
pipe1 = std::move(pipe2);
pipe1 = std::move(pipe6);
#endif // defined(ASIO_HAS_MOVE)

// basic_io_object functions.
Expand Down
4 changes: 4 additions & 0 deletions asio/src/tests/unit/writable_pipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,17 @@ void test()

#if defined(ASIO_HAS_MOVE)
writable_pipe pipe5(std::move(pipe4));

basic_writable_pipe<io_context::executor_type> pipe6(ioc);
writable_pipe pipe7(std::move(pipe6));
#endif // defined(ASIO_HAS_MOVE)

// basic_writable_pipe operators.

#if defined(ASIO_HAS_MOVE)
pipe1 = writable_pipe(ioc);
pipe1 = std::move(pipe2);
pipe1 = std::move(pipe6);
#endif // defined(ASIO_HAS_MOVE)

// basic_io_object functions.
Expand Down

0 comments on commit 8606891

Please sign in to comment.