Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

The use of throw() on so many functions is probably not a good idea for two reasons. First, it obligates your interface to never throw no matter how you might wish to re-implement the functions later. In almost every case, that's not really helpful because the compiler can often figure out for itself whether a function is noexcept or not. Second, it doesn't matter much for performance for many compilers. See this question this question for more views on this topic.

The use of throw() on so many functions is probably not a good idea for two reasons. First, it obligates your interface to never throw no matter how you might wish to re-implement the functions later. In almost every case, that's not really helpful because the compiler can often figure out for itself whether a function is noexcept or not. Second, it doesn't matter much for performance for many compilers. See this question for more views on this topic.

The use of throw() on so many functions is probably not a good idea for two reasons. First, it obligates your interface to never throw no matter how you might wish to re-implement the functions later. In almost every case, that's not really helpful because the compiler can often figure out for itself whether a function is noexcept or not. Second, it doesn't matter much for performance for many compilers. See this question for more views on this topic.

finally fixed the mix algorithm
Source Link
Edward
  • 67.2k
  • 4
  • 120
  • 284
void Game::sortByAlternatingScore() throw()
{
 std::sort(m_players.begin(), m_players.end(), [](const Player& p1, const Player& p2) {return p1.score > p2.score; });
 auto start = ++m_players.begin();
 auto halfsize =if (m_players.endsize() -< start3)/2; {
 auto upper = start+halfsize; return;
 std::reverse(upper, m_players.end());}
 for (auto ifirst=m_players.begin()+1; = halfsize; i; --i, ++upper, ++start) {
 std::swap(*start,first *upper!= m_players.end(); ++first) {
 }
 std::swapreverse(*startfirst, *m_players.end(start-1));
 }
}
void Game::sortByAlternatingScore() throw()
{
 std::sort(m_players.begin(), m_players.end(), [](const Player& p1, const Player& p2) {return p1.score > p2.score; });
 auto start = ++m_players.begin();
 auto halfsize = (m_players.end() - start)/2;
 auto upper = start+halfsize;
 std::reverse(upper, m_players.end());
 for (auto i = halfsize; i; --i, ++upper, ++start) {
 std::swap(*start, *upper);
 }
 std::swap(*start, *(start-1));
}
void Game::sortByAlternatingScore() throw()
{
 std::sort(m_players.begin(), m_players.end(), [](const Player& p1, const Player& p2) {return p1.score > p2.score; });
 if (m_players.size() < 3) {
  return;
 }
 for (auto first=m_players.begin()+1; first != m_players.end(); ++first) {
 std::reverse(first, m_players.end());
 }
}
cleaned up alternating code
Source Link
Edward
  • 67.2k
  • 4
  • 120
  • 284
void Game::sortByAlternatingScore() throw()
{
 std::sort(m_players.begin(), m_players.end(), [](const Player& p1, const Player& p2) {return p1.score > p2.score; });
 auto halfsizestart = m_players++m_players.sizebegin()/2;;
 std::reverse(m_players.begin()+halfsize,auto halfsize = (m_players.end() - start);/2;
 auto uppperupper = halfsize;start+halfsize;
 forstd::reverse(upper, m_players.end(size_t));
 i = 1; for (auto i <= halfsize; ++ii; --i, ++upper, ++start) {
 std::swap(m_players[i]*start, m_players[upper]*upper);
 }
 if (halfsize > 1 && 0 == (m_players.size() & 1)) {
 std::swap(m_players[halfsize]*start, m_players[halfsize*(start-1]1));
 }
}
void Game::sortByAlternatingScore() throw()
{
 std::sort(m_players.begin(), m_players.end(), [](const Player& p1, const Player& p2) {return p1.score > p2.score; });
 auto halfsize = m_players.size()/2;
 std::reverse(m_players.begin()+halfsize, m_players.end());
 auto uppper = halfsize;
 for (size_t i = 1; i < halfsize; ++i, ++upper) {
 std::swap(m_players[i], m_players[upper]);
 }
 if (halfsize > 1 && 0 == (m_players.size() & 1)) {
 std::swap(m_players[halfsize], m_players[halfsize-1]);
 }
}
void Game::sortByAlternatingScore() throw()
{
 std::sort(m_players.begin(), m_players.end(), [](const Player& p1, const Player& p2) {return p1.score > p2.score; });
 auto start = ++m_players.begin();
 auto halfsize = (m_players.end() - start)/2;
 auto upper = start+halfsize;
 std::reverse(upper, m_players.end());
 for (auto i = halfsize; i; --i, ++upper, ++start) {
 std::swap(*start, *upper);
 }
 std::swap(*start, *(start-1));
}
fix alternation
Source Link
Edward
  • 67.2k
  • 4
  • 120
  • 284
Loading
removed incorrect point
Source Link
Edward
  • 67.2k
  • 4
  • 120
  • 284
Loading
Source Link
Edward
  • 67.2k
  • 4
  • 120
  • 284
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /