aoc24: day05a split sections

rules and updates
This commit is contained in:
2024-12-05 16:38:03 +01:00
parent 1c6bbc6cef
commit 8df8cbb0e4
8 changed files with 1886 additions and 28 deletions
+81 -2
View File
@@ -1,11 +1,90 @@
#ifndef AOC_AOC_HPP
#define AOC_AOC_HPP
#include <type_traits>
#include <cstddef>
#include <limits>
#include <numbers>
#include <memory>
#include <system_error>
#include <expected>
#include <fstream>
#include <ranges>
#include <vector>
#include <string_view>
namespace aoc {
auto entry([[maybe_unused]]std::vector<std::string_view> const& args) -> void;
namespace types {
using f32 = float;
using f64 = double;
using b8 = bool;
using u8 = std::uint8_t;
using u16 = std::uint16_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using i8 = std::int8_t;
using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;
using c8 = char;
}
using f32 = types::f32;
using f64 = types::f64;
using b8 = types::b8;
using u8 = types::u8;
using u16 = types::u16;
using u32 = types::u32;
using u64 = types::u64;
using i8 = types::i8;
using i16 = types::i16;
using i32 = types::i32;
using i64 = types::i64;
using c8 = types::c8;
template <typename T>
concept Integral = std::is_integral<T>::value;
// Aliases
namespace nums = std::numbers;
template <typename T>
using lim = std::numeric_limits<T>;
inline constexpr auto pi = std::numbers::pi;
template <typename T>
inline constexpr auto pi_v = std::numbers::pi_v<T>;
struct error {
std::string msg;
std::error_code err;
};
inline auto make_error(std::string const& str, std::errc ec) -> std::unexpected<error> {
return std::unexpected(error{str, std::make_error_code(ec)});
}
auto read_text(std::string const& path) -> std::expected<std::string, aoc::error> {
std::fstream strm(path, std::ios::in | std::ios::binary);
if (!strm.is_open())
return aoc::make_error(path, std::errc::no_such_file_or_directory);
return std::string{
std::istreambuf_iterator<c8>(strm),
std::istreambuf_iterator<c8>()
};
}
// ranges and view aliases
template <typename T>
using vec = std::vector<T>;
}
#endif // !AOC_AOC_HPP