-
Notifications
You must be signed in to change notification settings - Fork 348
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
[BUG] sw::redis::Subscriber is move-assignable/constructable but does not have a default constructor #409
Comments
NO. You should not take the moved object as a valid An empty Regards |
A moved Subscriber has unspecified state means that
No offense but you seem to have a misunderstanding about move semantics about non-copyable objects. You think all STL objects behave like this, let's have a look at a typical example in c++11 specification https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3690.pdf
And Objects like
See also: |
No. The state is unspecified, but still valid, so that, as I mentioned above, you can only destroy it or re-assign it. Check tihs for detail.
My comment above mentioned: This is also how C++ move semantic works, and all STL objects behave (unless otherwise specified). It seems that you missed the sentence in the parentheses: unless otherwise specified. Some STL objects indeed ensure that the moved-from object will be in empty state (obviously, Some other examples:
The standard you mention above explicit states that string's move constructor make the moved-from string in a valid but unspecified state.
Since it's not specified, compilers are free to do anything, e.g. make the moved-from string empty. However, it's not guarantee by the standard, and the code is not portable, and you should not depend on the behavior. The underlying implementation might change in the future, or other compilers might have different behaviors. Regards |
Subscriber is a typically move-only class, so the Even a moved Subscriber can be unspecified, I still see no reason not providing a default constructor. |
We almost missed the point, the point is about the default constructor rather than the moved state.
|
This is some interesting discussion on a similar problem. Regards |
Thanks for following this topic that could be kinda esthetics-based. If I didn't get it wrong,
Thanks. |
However, the designing philosophy of STL never mentioned that an STL class must have a default constructor. For example, some members in
The problem is, so far, I do not find a default constructed Sorry for the late reply, too busy these days... Regards |
Sorry but, IMO, exceptions aren't good example for that, while good examples should,
Thanks. |
In fact, the compiler will construct the default constructor as needed。 |
@wb2712 No. The default contructor won't be generated if there are user defined constructor or a default constructor cannot be generated (e.g. has a base class that can not be default constructed) |
How can I define a When I using Sorry. I don't quite understand what you're saying, can you give me more details. |
@witeyou Try the following code:
Regards |
@witeyou You can but I can't agree that it's good practice. |
Describe the bug
sw::redis::Subscriber
has an empty state, but does not have a default constructor (sw::redis::Subscriber::Subscriber()
) to make one.sw::redis::Subscriber
does not haveSubscriber()
, but does haveSubscriber& operator= (Subscriber&& other)
andSubscriber(Subscriber&& other)
which is expected to make the other object an empty Subscriber.If the class has an empty state, user should be allow to create one.
So that the following code could be valid.
The text was updated successfully, but these errors were encountered: