1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-08-05 08:26:28 +00:00

Adopt std::ranges::copy where it is trivial to do so.

This commit is contained in:
Thomas Harte
2025-04-25 22:17:07 -04:00
parent de78fb7a1c
commit 03eb381b3b
8 changed files with 28 additions and 19 deletions

View File

@@ -9,6 +9,8 @@
#include "Tape.hpp"
#include "Storage/Tape/Parsers/Commodore.hpp"
#include <algorithm>
using namespace Analyser::Static::Commodore;
std::vector<File> Analyser::Static::Commodore::GetFiles(Storage::Tape::TapeSerialiser &serialiser, TargetPlatform::Type type) {
@@ -37,7 +39,7 @@ std::vector<File> Analyser::Static::Commodore::GetFiles(Storage::Tape::TapeSeria
header = parser.get_next_header(serialiser);
if(!header) continue;
if(header->type != Storage::Tape::Commodore::Header::DataBlock) break;
std::copy(header->data.begin(), header->data.end(), std::back_inserter(new_file.data));
std::ranges::copy(header->data, std::back_inserter(new_file.data));
}
}
break;

View File

@@ -16,6 +16,8 @@
#include "Outputs/Log.hpp"
#include "Activity/Observer.hpp"
#include <algorithm>
namespace Archimedes {
/// Provides the mask with all bits set in the range [start, end], where start must be >= end.
@@ -53,9 +55,8 @@ struct MemoryController {
// Copy in as many times as it'll fit.
std::size_t base = 0;
while(base < rom_.size()) {
std::copy(
rom.begin(),
rom.end(),
std::ranges::copy(
rom,
rom_.begin() + base);
base += rom.size();
}

View File

@@ -10,6 +10,8 @@
#include "Processors/Z80/Z80.hpp"
#include <algorithm>
namespace {
static constexpr uint16_t initial_pc = 0x0000;
@@ -28,7 +30,7 @@ struct CapturingZ80: public CPU::Z80::BusHandler {
template <typename Collection> CapturingZ80(const Collection &code) : z80_(*this) {
// Take a copy of the code.
std::copy(code.begin(), code.end(), ram_);
std::ranges::copy(code, ram_);
code_length_ = uint16_t(code.size());
// Skip the three cycles the Z80 spends on a reset, and

View File

@@ -742,7 +742,7 @@ int main(int argc, char *argv[]) {
}
if(!file) {
std::copy(rom_checked_paths.begin(), rom_checked_paths.end(), std::back_inserter(checked_paths));
std::ranges::copy(rom_checked_paths, std::back_inserter(checked_paths));
continue;
}
@@ -757,7 +757,7 @@ int main(int argc, char *argv[]) {
if(read == data.size()) {
results[description.name] = std::move(data);
} else {
std::copy(rom_checked_paths.begin(), rom_checked_paths.end(), std::back_inserter(checked_paths));
std::ranges::copy(rom_checked_paths, std::back_inserter(checked_paths));
}
}
}

View File

@@ -284,7 +284,7 @@ std::string Reflection::Struct::description() const {
/* Contractually, this serialises as BSON. */
std::vector<uint8_t> Reflection::Struct::serialise() const {
auto push_name = [] (std::vector<uint8_t> &result, const std::string &name) {
std::copy(name.begin(), name.end(), std::back_inserter(result));
std::ranges::copy(name, std::back_inserter(result));
result.push_back(0);
};
@@ -312,7 +312,7 @@ std::vector<uint8_t> Reflection::Struct::serialise() const {
const uint32_t string_length = uint32_t(text.size() + 1);
push_int(string_length);
std::copy(text.begin(), text.end(), std::back_inserter(result));
std::ranges::copy(text, std::back_inserter(result));
result.push_back(0);
};
@@ -387,7 +387,7 @@ std::vector<uint8_t> Reflection::Struct::serialise() const {
auto source = reinterpret_cast<const std::vector<uint8_t> *>(get(key));
push_int(uint32_t(source->size()));
result.push_back(0x00);
std::copy(source->begin(), source->end(), std::back_inserter(result));
std::ranges::copy(*source, std::back_inserter(result));
return;
}
@@ -399,7 +399,7 @@ std::vector<uint8_t> Reflection::Struct::serialise() const {
const Reflection::Struct *const child = reinterpret_cast<const Reflection::Struct *>(get(key));
const auto sub_document = child->serialise();
std::copy(sub_document.begin(), sub_document.end(), std::back_inserter(result));
std::ranges::copy(sub_document, std::back_inserter(result));
return;
}
@@ -441,7 +441,7 @@ std::vector<uint8_t> Reflection::Struct::serialise() const {
}
wrap_object(array);
std::copy(array.begin(), array.end(), std::back_inserter(result));
std::ranges::copy(array, std::back_inserter(result));
} else {
append(result, key, key, type, 0);
}

View File

@@ -8,11 +8,12 @@
#include "CSL.hpp"
#include <algorithm>
#include <cctype>
#include <fstream>
#include <set>
#include <sstream>
#include <unordered_map>
#include <set>
#include "Machines/AmstradCPC/Keyboard.hpp"
@@ -348,8 +349,8 @@ std::vector<CSL::Instruction> CSL::parse(const std::string &file_name) {
std::vector<KeyEvent> down;
std::vector<KeyEvent> up;
while(append_typed(down, up, stream)) {
std::copy(down.begin(), down.end(), std::back_inserter(argument));
std::copy(up.begin(), up.end(), std::back_inserter(argument));
std::ranges::copy(down, std::back_inserter(argument));
std::ranges::copy(up, std::back_inserter(argument));
down.clear();
up.clear();
}

View File

@@ -10,6 +10,7 @@
#include "Storage/Disk/Encodings/MFM/Parser.hpp"
#include <algorithm>
#include <iostream>
using namespace Storage::Disk;
@@ -113,7 +114,7 @@ std::optional<FAT::Volume> FAT::GetVolume(const std::shared_ptr<Storage::Disk::D
if(!fat_sector || fat_sector->samples.empty() || fat_sector->samples[0].size() != volume.bytes_per_sector) {
return std::nullopt;
}
std::copy(fat_sector->samples[0].begin(), fat_sector->samples[0].end(), std::back_inserter(source_fat));
std::ranges::copy(fat_sector->samples[0], std::back_inserter(source_fat));
}
// Decode the FAT.
@@ -135,7 +136,7 @@ std::optional<FAT::Volume> FAT::GetVolume(const std::shared_ptr<Storage::Disk::D
if(!sector || sector->samples.empty() || sector->samples[0].size() != volume.bytes_per_sector) {
return std::nullopt;
}
std::copy(sector->samples[0].begin(), sector->samples[0].end(), std::back_inserter(root_directory));
std::ranges::copy(sector->samples[0], std::back_inserter(root_directory));
}
volume.root_directory = directory_from(root_directory);
@@ -161,7 +162,7 @@ std::optional<std::vector<uint8_t>> FAT::GetFile(const std::shared_ptr<Storage::
if(!sector_contents || sector_contents->samples.empty() || sector_contents->samples[0].size() != volume.bytes_per_sector) {
return std::nullopt;
}
std::copy(sector_contents->samples[0].begin(), sector_contents->samples[0].end(), std::back_inserter(contents));
std::ranges::copy(sector_contents->samples[0], std::back_inserter(contents));
}
cluster = volume.fat[cluster];

View File

@@ -9,6 +9,8 @@
#include "DirectAccessDevice.hpp"
#include "Outputs/Log.hpp"
#include <algorithm>
using namespace SCSI;
namespace {
@@ -30,7 +32,7 @@ bool DirectAccessDevice::read(const Target::CommandState &state, Target::Respond
std::vector<uint8_t> output = device_->get_block(specs.address);
for(uint32_t offset = 1; offset < specs.number_of_blocks; ++offset) {
const auto next_block = device_->get_block(specs.address + offset);
std::copy(next_block.begin(), next_block.end(), std::back_inserter(output));
std::ranges::copy(next_block, std::back_inserter(output));
}
responder.send_data(std::move(output), [] (const Target::CommandState &, Target::Responder &responder) {