Skip to content

Sub method#2

Open
vanbear wants to merge 1 commit intodevelopfrom
dwas_sub
Open

Sub method#2
vanbear wants to merge 1 commit intodevelopfrom
dwas_sub

Conversation

@vanbear
Copy link
Copy Markdown
Collaborator

@vanbear vanbear commented Mar 2, 2018

Dodałem metodę sub

testest
Copy link
Copy Markdown
Owner

@jpola jpola left a comment

Choose a reason for hiding this comment

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

Zmienić implementację na nieco lepszą ;)

Comment thread vector.cpp
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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants