Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@ void swap(vector &first, vector &second) {
swap(first.data, second.data);
}

vector sub(const vector &first, const vector &second){
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To nie będzie działało. Plan na tą funkcję jest taki.

  1. Sprawdzić czy długość wektora first == długości wektora second.
  2. Stworzyć wektor przechowujący wynik odejmowania
  3. 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;
}

return first.data-second.data;
}


}// namespace ismk