mirror of
https://github.com/Z3Prover/z3
synced 2026-02-09 18:40:51 +00:00
Extend std::span adoption to utility and AST functions (#8271)
* Initial plan * Add std::span to utility functions (buffer, ref_buffer, permutation, util) Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> * Add std::span to ast_manager array ref functions Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> * Fix: Use consistent int loop variable in apply_permutation Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
This commit is contained in:
parent
4681c51413
commit
b0313ca80a
5 changed files with 89 additions and 29 deletions
|
|
@ -28,6 +28,7 @@ Revision History:
|
|||
#include <functional>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <span>
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
#define SIZE_MAX std::numeric_limits<std::size_t>::max()
|
||||
|
|
@ -360,14 +361,20 @@ public:
|
|||
};
|
||||
|
||||
template<typename T>
|
||||
void shuffle(unsigned sz, T * array, random_gen & gen) {
|
||||
int n = sz;
|
||||
void shuffle(std::span<T> array, random_gen & gen) {
|
||||
int n = array.size();
|
||||
while (--n > 0) {
|
||||
int k = gen() % (n + 1);
|
||||
std::swap(array[n], array[k]);
|
||||
}
|
||||
}
|
||||
|
||||
// Backward compatibility overload
|
||||
template<typename T>
|
||||
void shuffle(unsigned sz, T * array, random_gen & gen) {
|
||||
shuffle(std::span<T>(array, sz), gen);
|
||||
}
|
||||
|
||||
void fatal_error(int error_code);
|
||||
|
||||
void set_fatal_error_handler(void (*pfn)(int error_code));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue