Conversation
testest
jpola
requested changes
Mar 2, 2018
Owner
jpola
left a comment
There was a problem hiding this comment.
Zmienić implementację na nieco lepszą ;)
| swap(first.data, second.data); | ||
| } | ||
|
|
||
| vector sub(const vector &first, const vector &second){ |
Owner
There was a problem hiding this comment.
To nie będzie działało. Plan na tą funkcję jest taki.
- Sprawdzić czy długość wektora first == długości wektora second.
- Stworzyć wektor przechowujący wynik odejmowania
- Zwrócić wektor
Na przykład:
vector sub(const vector& first, const vector &second) {
vector result_vector(0, 0)
if (first.get_size() != second.get_size())
std::string err_msg ("Vectors are not equal size");
throw std::logic_error(err_msg);
}
vector result_vec(first.get_size(), 0);
for ( std::size_t i = 0; i < first.get_size(); ++i) {
result_vec[i] = first[i] - second[i];
}
//RVO - return value optimization. This object is temporary
// so if we are returning it, it will be actually moved.
return result_vec;
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Dodałem metodę sub