Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing operators and ctors for http_request and http_response #1668

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

evilenzo
Copy link

Solves this issue: #1667

Comment on lines 553 to 605
/// <summary>
/// Constructs a response object
/// </summary>
/// <returns>A new HTTP response.</returns>
http_response(const http_response& _Other) : _m_impl(_Other._m_impl) {}

/// <summary>
/// Constructs a response object
/// </summary>
/// <returns>A new HTTP response.</returns>
http_response(http_response&& _Other) : _m_impl(std::move(_Other._m_impl)) {}

/// <summary>Replaces the contents of one <c>http_request</c> object with another.</summary>
/// <param name="_Other">The source <c>http_request</c> object.</param>
/// <remarks>
/// As <c>http_request</c> behaves like a smart pointer, after a copy assignment, this <c>http_request</c>
/// objects represents the same actual http_request as <paramref name="_Other"/> does.
/// </remarks>
/// <returns>A new HTTP response.</returns>
http_response& operator=(const http_response& _Other)
{
if (this != &_Other)
{
_m_impl = _Other._m_impl;
}
return *this;
}

/// <summary>
/// Destructor frees any held resources.
/// </summary>
~http_response() = default;

/// <summary>Replaces the contents of one <c>http_request</c> object with another.</summary>
/// <param name="_Other">The source <c>http_request</c> object.</param>
/// <remarks>
/// As <c>http_request</c> behaves like a smart pointer, after a copy assignment, this <c>http_request</c>
/// objects represents the same actual http_request as <paramref name="_Other"/> does.
/// </remarks>
/// <returns>A new HTTP response.</returns>
http_response& operator=(http_response&& _Other)
{
if (this != &_Other)
{
_m_impl = std::move(_Other._m_impl);
}
return *this;
}

/// <summary>
/// Destructor frees any held resources.
/// </summary>
~http_response() = default;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't appear to do anything over just accepting the compiler's defaults. The original class has an empty destructor, which is somewhat redundant, not an excuse to add even more redundant stuff

@@ -853,7 +909,7 @@ class _http_request final : public http::details::http_msg_base, public std::ena

_ASYNCRTIMP _http_request(std::unique_ptr<http::details::_http_server_context> server_context);

virtual ~_http_request() {}
virtual ~_http_request() = default;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Comment on lines 1010 to 1070
/// <summary>
/// Constructs a <c>http_request</c> object.
/// </summary>
/// <param name="_Other">
/// The source <c>http_request</c> object.
/// </param>
http_request(const http_request& _Other) : _m_impl(_Other._m_impl) {}

/// <summary>
/// Constructs a <c>http_request</c> object.
/// </summary>
/// <param name="_Other">
/// The source <c>http_request</c> object.
/// </param>
http_request(http_request&& _Other) : _m_impl(_Other._m_impl) {}


/// <summary>
/// Replaces the contents of one <c>http_request</c> object with another.
/// </summary>
/// <param name="_Other">
/// The source <c>http_request</c> object.
/// </param>
/// <remarks>
/// As <c>http_request</c> behaves like a smart pointer, after a copy assignment, this <c>http_request</c>
/// objects represents the same actual http_request as <paramref name="_Other"/> does.
/// </remarks>
/**/
http_request& operator=(const http_request& _Other)
{
if (this != &_Other)
{
_m_impl = _Other._m_impl;
}
return *this;
}

/// <summary>
/// Replaces the contents of one <c>http_request</c> object with another.
/// </summary>
/// <param name="_Other">
/// The source <c>http_request</c> object.
/// </param>
/// <remarks>
/// As <c>http_request</c> behaves like a smart pointer, after a copy assignment, this <c>http_request</c>
/// objects represents the same actual http_request as <paramref name="_Other"/> does.
/// </remarks>
/**/
http_request& operator=(http_request&& _Other)
{
if (this != &_Other)
{
_m_impl = std::move(_Other._m_impl);
}
return *this;
}

/// <summary>
/// Destructor frees any held resources.
/// </summary>
~http_request() {}
~http_request() = default;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again not needed

@barcharcraz
Copy link
Member

This approach seems completely backwards, for starters it adds a bunch of (implicit) copy constructors and that's totally not necessary, and also, the new move constructor doesn't move!

It would be much better to stop defining an empty destructor (which is equivalent to what the compiler would do anyways) and just default the move constructor, so the shared pointer would get moved

@evilenzo
Copy link
Author

Ok. My point was to implement all functions of rule of five to not be aware if compiler won't generate move/copy ctors and assignment operators. If we wan't to produce less redunant code, we must follow standard which says that compiler will generate both copy and assignment functions if we doesn't have user-defined destructor. The main problem is this line. User-defined destructor means that compiler won't support us

@evilenzo
Copy link
Author

Also this file has other ctors and dtors that are defaulted. If it is the matter of style so why we won't change them to {} too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants