-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
base: master
Are you sure you want to change the base?
Conversation
Release/include/cpprest/http_msg.h
Outdated
/// <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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
Release/include/cpprest/http_msg.h
Outdated
/// <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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again not needed
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 |
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 |
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? |
Solves this issue: #1667