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
|
|
|
|
2017-11-24 17:18:43 +11:00
|
|
|
#include "./traits.hpp"
|
2019-03-18 16:18:27 +11:00
|
|
|
#include "../iterator/infix.hpp"
|
2016-03-11 12:48:19 +11:00
|
|
|
|
2023-07-21 14:20:49 +10:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct fmt::formatter<
|
|
|
|
T,
|
|
|
|
std::enable_if_t<cruft::is_coord_v<T>, char>
|
|
|
|
> {
|
|
|
|
constexpr format_parse_context::iterator
|
|
|
|
parse (format_parse_context &ctx)
|
|
|
|
{
|
|
|
|
return ctx.begin ();
|
|
|
|
}
|
|
|
|
|
|
|
|
format_context::iterator
|
|
|
|
format (T const &val, format_context &ctx)
|
|
|
|
{
|
|
|
|
return fmt::format_to (
|
|
|
|
ctx.out (),
|
|
|
|
"[{}]",
|
|
|
|
fmt::join (std::begin (val), std::end (val), ", ")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|