48enum class Type : std::uint_fast8_t {
65[[nodiscard]]
auto from_string(std::string_view text)
66 -> std::expected<Type, std::string>;
72[[nodiscard, gnu::const]]
constexpr auto to_char(
73 Type type,
bool uppercase =
true)
85struct std::formatter<
chess::pieces::Type> final {
86 template <
typename ParseContext>
88 constexpr auto parse(ParseContext& ctx) ->
typename ParseContext::iterator
93 template <
typename FormatContext>
97 ->
typename FormatContext::iterator
99 return std::format_to(ctx.out(),
"{}", to_char(piece));
122constexpr auto to_char(
const Type type,
const bool uppercase) ->
char
125 static constexpr std::string_view upperChars {
"PNBRQK" };
127 return upperChars.at(std::to_underlying(type));
130 static constexpr std::string_view lowerChars {
"pnbrqk" };
132 return lowerChars.at(std::to_underlying(type));
136 -> std::expected<Type, std::string>
138 if (text.length() != 1uz)
139 text = text.substr(0uz, 1uz);
141 switch (text.front()) {
142 case 'p': [[fallthrough]];
145 case 'n': [[fallthrough]];
148 case 'b': [[fallthrough]];
151 case 'r': [[fallthrough]];
154 case 'q': [[fallthrough]];
157 case 'k': [[fallthrough]];
161 return std::unexpected {
163 "Cannot parse piece type from invalid input string: {}",
auto from_string(std::string_view text) -> std::expected< Type, std::string >
constexpr auto to_char(Type type, bool uppercase=true) -> char