mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-26 21:30:31 +01:00
Small reading utility.
This commit is contained in:
@@ -27,7 +27,7 @@ namespace {
|
|||||||
for (auto entry = aoc2019::strtok(line); !line.empty() || !entry.empty(); entry = aoc2019::strtok(line)) {
|
for (auto entry = aoc2019::strtok(line); !line.empty() || !entry.empty(); entry = aoc2019::strtok(line)) {
|
||||||
const auto dir = DIRECTION_MAP.at(entry[0]);
|
const auto dir = DIRECTION_MAP.at(entry[0]);
|
||||||
std::size_t amount = 0;
|
std::size_t amount = 0;
|
||||||
std::from_chars(entry.data() + 1, entry.data() + entry.size(), amount);
|
aoc2019::from_chars(entry.substr(1), amount);
|
||||||
assert(amount > 0 && "Must have some valid direction");
|
assert(amount > 0 && "Must have some valid direction");
|
||||||
|
|
||||||
for (std::size_t i = 0; i < amount; ++i) {
|
for (std::size_t i = 0; i < amount; ++i) {
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <charconv>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
namespace aoc2019 {
|
namespace aoc2019 {
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline std::from_chars_result from_chars(std::string_view str, T& value) {
|
||||||
|
return std::from_chars(str.data(), str.data() + str.size(), value);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void combine_hash(std::size_t& seed, const T& o) {
|
void combine_hash(std::size_t& seed, const T& o) {
|
||||||
// Algorithm taken from boost::combine_hash.
|
// Algorithm taken from boost::combine_hash.
|
||||||
|
|||||||
Reference in New Issue
Block a user