91 lines
1.8 KiB
C++
91 lines
1.8 KiB
C++
#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>
|
|
|
|
namespace aoc {
|
|
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
|