Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Graphics
Gwenview
Commits
6dea0727
Commit
6dea0727
authored
Oct 29, 2022
by
Volker Krause
Browse files
Port away from std::random_shuffle, that's gone in C++17
parent
cac0b617
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/slideshow.cpp
View file @
6dea0727
...
...
@@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// STL
#include
<algorithm>
#include
<ctime>
#include
<random>
// Qt
#include
<QAction>
...
...
@@ -52,27 +53,6 @@ enum State {
WaitForEndOfUrl
,
};
/**
* This class generate random numbers which are not the same between two runs
* of Gwenview. See bug #132334
*/
class
RandomNumberGenerator
{
public:
RandomNumberGenerator
()
:
mSeed
(
time
(
nullptr
))
{
}
int
operator
()(
int
n
)
{
return
rand_r
(
&
mSeed
)
%
n
;
}
private:
unsigned
int
mSeed
;
};
struct
SlideShowPrivate
{
QTimer
*
mTimer
=
nullptr
;
State
mState
;
...
...
@@ -123,8 +103,9 @@ struct SlideShowPrivate {
void
initShuffledUrls
()
{
mShuffledUrls
=
mUrls
;
RandomNumberGenerator
generator
;
std
::
random_shuffle
(
mShuffledUrls
.
begin
(),
mShuffledUrls
.
end
(),
generator
);
std
::
random_device
rd
;
std
::
mt19937
generator
(
rd
());
std
::
shuffle
(
mShuffledUrls
.
begin
(),
mShuffledUrls
.
end
(),
generator
);
// Ensure the first url is different from the previous last one, so that
// last url does not stay visible twice longer than usual
if
(
mLastShuffledUrl
==
mShuffledUrls
.
first
()
&&
mShuffledUrls
.
count
()
>
1
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment