mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-17 08:06:59 +01:00
Merge bitcoin/bitcoin#29369: refactor: Allow CScript construction from any std::input_iterator
fa7b9b99a2refactor: Require std::input_iterator for all InputIterator in prevector (MarcoFalke)d444441900refactor: Allow CScript construction from any std::input_iterator (MarcoFalke) Pull request description: Currently only (pre)vector iterators and raw pointers are accepted. However, this makes it harder to construct from input iterators provided by other classes, such as `std::span`. Fix that. ACKs for top commit: delta1: reACKfa7b9b9achow101: ACKfa7b9b99a2hodlinator: ACKfa7b9b99a2ryanofsky: Code review ACKfa7b9b99a2Tree-SHA512: 2760861f8bce42fb27dc0825e61621cb157f1ac3619a0834df38eb8319b6dcf9de43d90397a4c160f43340880c1553df638848e9057a27c792214331243ef4a5
This commit is contained in:
@@ -5,13 +5,13 @@
|
|||||||
#ifndef BITCOIN_PREVECTOR_H
|
#ifndef BITCOIN_PREVECTOR_H
|
||||||
#define BITCOIN_PREVECTOR_H
|
#define BITCOIN_PREVECTOR_H
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cassert>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include <iterator>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
@@ -50,7 +50,6 @@ public:
|
|||||||
T* ptr{};
|
T* ptr{};
|
||||||
public:
|
public:
|
||||||
typedef Diff difference_type;
|
typedef Diff difference_type;
|
||||||
typedef T value_type;
|
|
||||||
typedef T* pointer;
|
typedef T* pointer;
|
||||||
typedef T& reference;
|
typedef T& reference;
|
||||||
using element_type = T;
|
using element_type = T;
|
||||||
@@ -102,7 +101,6 @@ public:
|
|||||||
const T* ptr{};
|
const T* ptr{};
|
||||||
public:
|
public:
|
||||||
typedef Diff difference_type;
|
typedef Diff difference_type;
|
||||||
typedef const T value_type;
|
|
||||||
typedef const T* pointer;
|
typedef const T* pointer;
|
||||||
typedef const T& reference;
|
typedef const T& reference;
|
||||||
using element_type = const T;
|
using element_type = const T;
|
||||||
@@ -212,7 +210,7 @@ private:
|
|||||||
std::fill_n(dst, count, value);
|
std::fill_n(dst, count, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename InputIterator>
|
template <std::input_iterator InputIterator>
|
||||||
void fill(T* dst, InputIterator first, InputIterator last) {
|
void fill(T* dst, InputIterator first, InputIterator last) {
|
||||||
while (first != last) {
|
while (first != last) {
|
||||||
new(static_cast<void*>(dst)) T(*first);
|
new(static_cast<void*>(dst)) T(*first);
|
||||||
@@ -231,7 +229,7 @@ public:
|
|||||||
fill(item_ptr(0), n, val);
|
fill(item_ptr(0), n, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename InputIterator>
|
template <std::input_iterator InputIterator>
|
||||||
void assign(InputIterator first, InputIterator last) {
|
void assign(InputIterator first, InputIterator last) {
|
||||||
size_type n = last - first;
|
size_type n = last - first;
|
||||||
clear();
|
clear();
|
||||||
@@ -254,7 +252,7 @@ public:
|
|||||||
fill(item_ptr(0), n, val);
|
fill(item_ptr(0), n, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename InputIterator>
|
template <std::input_iterator InputIterator>
|
||||||
prevector(InputIterator first, InputIterator last) {
|
prevector(InputIterator first, InputIterator last) {
|
||||||
size_type n = last - first;
|
size_type n = last - first;
|
||||||
change_capacity(n);
|
change_capacity(n);
|
||||||
@@ -383,7 +381,7 @@ public:
|
|||||||
fill(item_ptr(p), count, value);
|
fill(item_ptr(p), count, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename InputIterator>
|
template <std::input_iterator InputIterator>
|
||||||
void insert(iterator pos, InputIterator first, InputIterator last) {
|
void insert(iterator pos, InputIterator first, InputIterator last) {
|
||||||
size_type p = pos - begin();
|
size_type p = pos - begin();
|
||||||
difference_type count = last - first;
|
difference_type count = last - first;
|
||||||
|
|||||||
@@ -429,11 +429,11 @@ protected:
|
|||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CScript() = default;
|
CScript() = default;
|
||||||
CScript(const_iterator pbegin, const_iterator pend) : CScriptBase(pbegin, pend) { }
|
template <std::input_iterator InputIterator>
|
||||||
CScript(std::vector<unsigned char>::const_iterator pbegin, std::vector<unsigned char>::const_iterator pend) : CScriptBase(pbegin, pend) { }
|
CScript(InputIterator first, InputIterator last) : CScriptBase{first, last} { }
|
||||||
CScript(const unsigned char* pbegin, const unsigned char* pend) : CScriptBase(pbegin, pend) { }
|
|
||||||
|
|
||||||
SERIALIZE_METHODS(CScript, obj) { READWRITE(AsBase<CScriptBase>(obj)); }
|
SERIALIZE_METHODS(CScript, obj) { READWRITE(AsBase<CScriptBase>(obj)); }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user