2016-03-11 12:48:19 +11:00
|
|
|
/*
|
2018-08-04 15:14:06 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2016-03-11 12:48:19 +11:00
|
|
|
*
|
2019-03-18 16:18:27 +11:00
|
|
|
* Copyright 2016-2019 Danny Robson <danny@nerdcruft.net>
|
2016-03-11 12:48:19 +11:00
|
|
|
*/
|
|
|
|
|
2019-03-18 16:18:27 +11:00
|
|
|
#pragma once
|
2016-03-11 12:48:19 +11:00
|
|
|
|
2024-10-16 12:19:35 +11:00
|
|
|
#include <cruft/util/coord/traits.hpp>
|
|
|
|
#include <cruft/util/iterator/infix.hpp>
|
2016-03-11 12:48:19 +11:00
|
|
|
|
2023-07-21 14:20:49 +10:00
|
|
|
#include <fmt/format.h>
|
2024-10-16 12:19:35 +11:00
|
|
|
#include <fmt/ranges.h>
|
2023-07-21 14:20:49 +10:00
|
|
|
|
2017-08-28 12:25:23 +10:00
|
|
|
#include <cstddef>
|
2016-03-11 12:48:19 +11:00
|
|
|
#include <ostream>
|
2016-03-11 13:01:57 +11:00
|
|
|
#include <algorithm>
|
2016-03-11 12:48:19 +11:00
|
|
|
|
2024-10-16 12:19:35 +11:00
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
namespace cruft {
|
2016-03-11 12:48:19 +11:00
|
|
|
template <
|
2017-11-24 17:18:43 +11:00
|
|
|
typename K,
|
|
|
|
typename = std::enable_if_t<is_coord_v<K>,void>
|
2016-03-11 12:48:19 +11:00
|
|
|
>
|
|
|
|
std::ostream&
|
2017-11-24 17:18:43 +11:00
|
|
|
operator<< (std::ostream &os, const K &k)
|
2016-03-11 12:48:19 +11:00
|
|
|
{
|
|
|
|
os << "[";
|
|
|
|
std::transform (std::cbegin (k),
|
|
|
|
std::cend (k),
|
2019-03-18 16:18:27 +11:00
|
|
|
iterator::infix_iterator<typename K::value_type> (os, ", "),
|
2016-06-29 17:52:26 +10:00
|
|
|
[] (auto i) { return +i; });
|
2016-03-11 12:48:19 +11:00
|
|
|
os << "]";
|
|
|
|
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
}
|
2023-07-21 14:20:49 +10:00
|
|
|
|
|
|
|
|
2024-10-16 12:19:35 +11:00
|
|
|
template <typename T, typename Char>
|
|
|
|
requires (cruft::is_coord_v<T>)
|
|
|
|
struct fmt::range_format_kind<T, Char> :
|
|
|
|
std::integral_constant<fmt::range_format, fmt::range_format::disabled> {};
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T, typename Char>
|
|
|
|
requires (cruft::is_coord_v<std::remove_cvref_t<T>>)
|
|
|
|
struct fmt::formatter<T, Char> {
|
|
|
|
constexpr auto
|
2023-07-21 14:20:49 +10:00
|
|
|
parse (format_parse_context &ctx)
|
|
|
|
{
|
|
|
|
return ctx.begin ();
|
|
|
|
}
|
|
|
|
|
2024-10-16 12:19:35 +11:00
|
|
|
auto
|
|
|
|
format (T const &val, format_context &ctx) const
|
2023-07-21 14:20:49 +10:00
|
|
|
{
|
|
|
|
return fmt::format_to (
|
|
|
|
ctx.out (),
|
|
|
|
"[{}]",
|
|
|
|
fmt::join (std::begin (val), std::end (val), ", ")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|