From: Pavel Vainerman <pv@etersoft.ru>
To: ALT Linux Community general discussions <community@lists.altlinux.org>
Subject: [Comm] Ошибка (или нет?) в std::partition
Date: Fri, 25 Aug 2017 01:13:08 +0300
Message-ID: <101a26f1-1b29-ca8d-c1f3-d86b8797ef91@etersoft.ru> (raw)
Добрый день.
Обнаружил тут странное поведение у 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
next reply other threads:[~2017-08-24 22:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-24 22:13 Pavel Vainerman [this message]
2017-08-24 22:40 ` Alexey Borisenkov
2017-08-25 7:52 ` Pavel Vainerman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=101a26f1-1b29-ca8d-c1f3-d86b8797ef91@etersoft.ru \
--to=pv@etersoft.ru \
--cc=community@lists.altlinux.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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