-
Notifications
You must be signed in to change notification settings - Fork 1
Implement values #3
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
base: master
Are you sure you want to change the base?
Conversation
| Value::Value(const Vector_2& v) | ||
| : type_(Type::vector_2), | ||
| vector_2_(std::unique_ptr<const Vector_2>(new Vector_2(v))) | ||
| { |
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.
using new in member initialization is imo not a good idea. if construction fails because of memory allocation error and many members were initialized in this way, it is impossible to find which member caused the problem, and the resources for the members are leaked. furthermore, it makes it unclear which members need to be freed. However, since the new is within the construction of the unique_ptr the latter argument may not be valid, i'm not sure on this.
|
|
||
| Value& | ||
| Value::operator=(Value&& x) | ||
| { |
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.
doesn't a referenced reference implicitly get cast to a reference making this assignment operator redundant ?
| case Type::vector_2: | ||
| new (&vector_2_) | ||
| std::unique_ptr<const Vector_2>(new Vector_2(*x.vector_2_)); | ||
| break; |
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.
just for my information, why do you need the second 'new' here? couldnt you just construct using the x.vector_2_ directly ?
|
maybe it wasn't clear in our discussion on the math types, but I really urge you to remove the vector2 and matrix3 classes altogether. we will not use them often, they are only intended to reduce datatransfer but to a very small extend, and it increases the maintenance burden that is already considerable. |
Our ultimate goal here is to build an interpreter for a stack machine. The primary data structure in this stack machine is of course the stack. Our stack should be able to contain values of arbitrary types. To accomplish this, we now introduce the
Valuetype, which can take on several different types. ThisValuetype has been carefully designed to perform well on a stack (see the comments for details).Finally, the
is<T>andget<T>helper functions will allow us to use the Value class in a generic context. This will prove useful when we use templates to automatically wrap built-in functions.