Skip to content

Commit a8dbcd7

Browse files
C++ compatibility patch
allows compatibility from C++11 up to C++17
1 parent b280b52 commit a8dbcd7

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/wallet/wallet.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,28 @@
3636
#include <boost/algorithm/string/replace.hpp>
3737
#include <boost/thread.hpp>
3838

39+
#include <algorithm>
40+
// ================================================================
41+
// C++17 compatibility: std::random_shuffle was removed.
42+
// We provide a replacement that preserves the old behavior.
43+
// ================================================================
44+
template <typename RandomIt>
45+
static void RandomShuffleCompat(RandomIt first, RandomIt last)
46+
{
47+
#if __cplusplus >= 201703L
48+
// Manual shuffle using GetRandInt()
49+
if (first == last) return;
50+
auto n = last - first;
51+
for (decltype(n) i = n - 1; i > 0; --i) {
52+
std::swap(first[i], first[GetRandInt(i + 1)]);
53+
}
54+
#else
55+
// Old compilers still have std::random_shuffle
56+
std::random_shuffle(first, last, GetRandInt);
57+
#endif
58+
}
59+
60+
3961
std::vector<CWalletRef> vpwallets;
4062
/** Transaction fee set by the user */
4163
CFeeRate payTxFee(DEFAULT_TRANSACTION_FEE);
@@ -2392,7 +2414,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin
23922414
std::vector<CInputCoin> vValue;
23932415
CAmount nTotalLower = 0;
23942416

2395-
random_shuffle(vCoins.begin(), vCoins.end(), GetRandInt);
2417+
RandomShuffleCompat(vCoins.begin(), vCoins.end());
23962418

23972419
for (const COutput &output : vCoins)
23982420
{

0 commit comments

Comments
 (0)