-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Added copy constructor, move constructor and copy assignment operator. #826
Changes from 1 commit
8dd4845
5d5861e
952211b
a1a0e3c
a1a1cef
4fccbc9
89cef13
7d1bb44
3a3fd60
ddbfd81
a7ff69c
5542ae9
2e37a38
58cf0d9
c9e7fb0
f709ad6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,16 +203,16 @@ DTree<MatType, TagType>& DTree<MatType, TagType>::operator=(const DTree<MatType, | |
logVolume = obj.logVolume; | ||
bucketTag = obj.bucketTag; | ||
alphaUpper = obj.alphaUpper; | ||
|
||
//Copying the children | ||
left = new DTree(*obj.left); | ||
right = new DTree(*obj.right); | ||
|
||
return *this; | ||
} | ||
|
||
template <typename MatType, typename TagType> | ||
DTree<MatType, TagType>::DTree(DTree&& obj) | ||
DTree<MatType, TagType>::DTree(DTree&& obj) | ||
{ | ||
//Moving the values from object | ||
start = std::move(obj.start); | ||
|
@@ -229,14 +229,8 @@ DTree<MatType, TagType>::DTree(DTree&& obj) | |
logVolume = std::move(obj.logVolume); | ||
bucketTag = std::move(obj.bucketTag); | ||
alphaUpper = std::move(obj.alphaUpper); | ||
|
||
//Free the space allocated | ||
delete left; | ||
delete right; | ||
|
||
//Moving the children | ||
left = std::move(obj.left); | ||
right = std::move(obj.right); | ||
right = std::move(obj.right); | ||
|
||
//Set obj to default values | ||
obj.start = 0; | ||
|
@@ -256,11 +250,11 @@ DTree<MatType, TagType>::DTree(DTree&& obj) | |
|
||
} | ||
|
||
|
||
template <typename MatType, typename TagType> | ||
DTree<MatType, TagType>& DTree<MatType, TagType>::operator=(DTree<MatType, TagType>&& obj) | ||
{ | ||
//Moving the values from obj | ||
if (this != &obj){ | ||
//Moving the values from object | ||
start = std::move(obj.start); | ||
end = std::move(obj.end); | ||
maxVals = std::move(obj.maxVals); | ||
|
@@ -275,12 +269,12 @@ DTree<MatType, TagType>& DTree<MatType, TagType>::operator=(DTree<MatType, TagTy | |
logVolume = std::move(obj.logVolume); | ||
bucketTag = std::move(obj.bucketTag); | ||
alphaUpper = std::move(obj.alphaUpper); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't bother with |
||
|
||
//Free the space allocated | ||
delete left; | ||
delete right; | ||
|
||
//Moving the children | ||
//Moving children | ||
left = std::move(obj.left); | ||
right = std::move(obj.right); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you're just moving pointers here, you don't actually need to use |
||
|
||
|
@@ -299,10 +293,9 @@ DTree<MatType, TagType>& DTree<MatType, TagType>::operator=(DTree<MatType, TagTy | |
obj.alphaUpper = 0.0; | ||
obj.left = NULL; | ||
obj.right = NULL; | ||
} | ||
} | ||
|
||
|
||
// Root node initializers | ||
template <typename MatType, typename TagType> | ||
DTree<MatType, TagType>::DTree(const StatType& maxVals, | ||
|
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.
I think the test to see if this is the same as the object being copied is unnecessary.