ALT Linux Community general discussions
 help / color / mirror / Atom feed
* [Comm] Ошибка (или нет?) в std::partition
@ 2017-08-24 22:13 Pavel Vainerman
  2017-08-24 22:40 ` Alexey Borisenkov
  0 siblings, 1 reply; 3+ messages in thread
From: Pavel Vainerman @ 2017-08-24 22:13 UTC (permalink / raw)
  To: ALT Linux Community general discussions

Добрый день.

Обнаружил тут странное поведение у std::partition().
Вот тестовый код (c++11).

#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>

using namespace std;

void print( vector<int>& v )
{
	for( const auto& i: v )
		cout << setw(3) << i;
	cout << endl;
}

int main()
{
	vector<int> v =  { -10, 0, -4, 5, -2 , 0, 3, 1, 7, 8, 9 };

	print(v);
	std::partition(v.begin(),v.end(),[](int v){ return v<0; });
	print(v);

	return 0;
}

Вот результат (первая строка, исходный вектор, вторая преобразованный,
опорный элемент 0).

-10  0 -4  5 -2  0  3  1  7  8  9
-10 -2 -4  5  0  0  3  1  7  8  9

Так вот смущает меня почему "5" не правее нулей?
Может ли кто-нибудь пояснить, почему так?


-- 
Pavel Vainerman
www.etersoft.ru


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-08-25  7:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-24 22:13 [Comm] Ошибка (или нет?) в std::partition Pavel Vainerman
2017-08-24 22:40 ` Alexey Borisenkov
2017-08-25  7:52   ` Pavel Vainerman

ALT Linux Community general discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
		mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
	public-inbox-index community

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.community


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git