Skip to content

Commit 99b06b7

Browse files
committed
Merge bitcoin/bitcoin#29369: refactor: Allow CScript construction from any std::input_iterator
fa7b9b9 refactor: Require std::input_iterator for all InputIterator in prevector (MarcoFalke) d444441 refactor: 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: reACK fa7b9b9 achow101: ACK fa7b9b9 hodlinator: ACK fa7b9b9 ryanofsky: Code review ACK fa7b9b9 Tree-SHA512: 2760861f8bce42fb27dc0825e61621cb157f1ac3619a0834df38eb8319b6dcf9de43d90397a4c160f43340880c1553df638848e9057a27c792214331243ef4a5
2 parents dc90542 + fa7b9b9 commit 99b06b7

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/prevector.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
#ifndef BITCOIN_PREVECTOR_H
66
#define BITCOIN_PREVECTOR_H
77

8-
#include <assert.h>
9-
#include <cstdlib>
10-
#include <stdint.h>
11-
#include <string.h>
12-
138
#include <algorithm>
9+
#include <cassert>
1410
#include <cstddef>
11+
#include <cstdint>
12+
#include <cstdlib>
13+
#include <cstring>
14+
#include <iterator>
1515
#include <type_traits>
1616
#include <utility>
1717

@@ -50,7 +50,6 @@ class prevector {
5050
T* ptr{};
5151
public:
5252
typedef Diff difference_type;
53-
typedef T value_type;
5453
typedef T* pointer;
5554
typedef T& reference;
5655
using element_type = T;
@@ -102,7 +101,6 @@ class prevector {
102101
const T* ptr{};
103102
public:
104103
typedef Diff difference_type;
105-
typedef const T value_type;
106104
typedef const T* pointer;
107105
typedef const T& reference;
108106
using element_type = const T;
@@ -212,7 +210,7 @@ class prevector {
212210
std::fill_n(dst, count, value);
213211
}
214212

215-
template<typename InputIterator>
213+
template <std::input_iterator InputIterator>
216214
void fill(T* dst, InputIterator first, InputIterator last) {
217215
while (first != last) {
218216
new(static_cast<void*>(dst)) T(*first);
@@ -231,7 +229,7 @@ class prevector {
231229
fill(item_ptr(0), n, val);
232230
}
233231

234-
template<typename InputIterator>
232+
template <std::input_iterator InputIterator>
235233
void assign(InputIterator first, InputIterator last) {
236234
size_type n = last - first;
237235
clear();
@@ -254,7 +252,7 @@ class prevector {
254252
fill(item_ptr(0), n, val);
255253
}
256254

257-
template<typename InputIterator>
255+
template <std::input_iterator InputIterator>
258256
prevector(InputIterator first, InputIterator last) {
259257
size_type n = last - first;
260258
change_capacity(n);
@@ -383,7 +381,7 @@ class prevector {
383381
fill(item_ptr(p), count, value);
384382
}
385383

386-
template<typename InputIterator>
384+
template <std::input_iterator InputIterator>
387385
void insert(iterator pos, InputIterator first, InputIterator last) {
388386
size_type p = pos - begin();
389387
difference_type count = last - first;

src/script/script.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,11 @@ class CScript : public CScriptBase
429429
}
430430
return *this;
431431
}
432+
432433
public:
433434
CScript() = default;
434-
CScript(const_iterator pbegin, const_iterator pend) : CScriptBase(pbegin, pend) { }
435-
CScript(std::vector<unsigned char>::const_iterator pbegin, std::vector<unsigned char>::const_iterator pend) : CScriptBase(pbegin, pend) { }
436-
CScript(const unsigned char* pbegin, const unsigned char* pend) : CScriptBase(pbegin, pend) { }
435+
template <std::input_iterator InputIterator>
436+
CScript(InputIterator first, InputIterator last) : CScriptBase{first, last} { }
437437

438438
SERIALIZE_METHODS(CScript, obj) { READWRITE(AsBase<CScriptBase>(obj)); }
439439

0 commit comments

Comments
 (0)