Skip to content

Commit

Permalink
Replace deprecated std::random_shuffle by std::shuffle
Browse files Browse the repository at this point in the history
This fixes the following clang-tidy warning:

    src/rssfeed.cpp:338:8: warning: 'random_shuffle<__gnu_cxx::__normal_iterator<std::shared_ptr<newsboat::RssItem> *, std::vector<std::shared_ptr<newsboat::RssItem>>>>' is deprecated: use 'std::shuffle' instead [clang-diagnostic-deprecated-declarations]
                    std::random_shuffle(items_.begin(), items_.end());
                         ^
    /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_algo.h:4539:5: note: 'random_shuffle<__gnu_cxx::__normal_iterator<std::shared_ptr<newsboat::RssItem> *, std::vector<std::shared_ptr<newsboat::RssItem>>>>' has been explicitly marked deprecated here
        _GLIBCXX14_DEPRECATED_SUGGEST("std::shuffle")
        ^
    /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/x86_64-linux-gnu/c++/12/bits/c++config.h:112:45: note: expanded from macro '_GLIBCXX14_DEPRECATED_SUGGEST'
                                                ^
    /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/x86_64-linux-gnu/c++/12/bits/c++config.h:96:19: note: expanded from macro '_GLIBCXX_DEPRECATED_SUGGEST'
      __attribute__ ((__deprecated__ ("use '" ALT "' instead")))
                      ^
  • Loading branch information
Minoru committed Feb 17, 2024
1 parent 3653e6b commit c4b5b56
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/rssfeed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
#include <functional>
#include <iostream>
#include <langinfo.h>
#include <random>
#include <sstream>
#include <sys/utsname.h>
#include <string.h>
#include <sys/utsname.h>
#include <time.h>

#include "cache.h"
Expand Down Expand Up @@ -335,7 +336,9 @@ void RssFeed::sort_unlocked(const ArticleSortStrategy& sort_strategy)
});
break;
case ArtSortMethod::RANDOM:
std::random_shuffle(items_.begin(), items_.end());
std::random_device rd;
std::default_random_engine rng(rd());
std::shuffle(items_.begin(), items_.end(), rng);
break;
}
}
Expand Down

0 comments on commit c4b5b56

Please sign in to comment.