12namespace QXmpp::Private {
15constexpr bool HasShrinkToFit =
requires(
const T &t) {
20constexpr bool HasSqueeze =
requires(
const T &t) {
24template<
typename OutputVector,
typename InputVector,
typename Converter>
25auto transform(
const InputVector &input, Converter convert)
28 if constexpr (std::ranges::sized_range<InputVector>) {
29 output.reserve(input.size());
31 for (
const auto &value : input) {
32 output.push_back(std::invoke(convert, value));
37template<
typename OutputVector,
typename InputVector,
typename Converter>
38auto transformFilter(
const InputVector &input, Converter convert)
41 if constexpr (std::ranges::sized_range<InputVector>) {
42 output.reserve(input.size());
44 for (
const auto &value : input) {
45 if (
const std::optional<std::decay_t<
decltype(value)>> result = std::invoke(convert, value)) {
46 output.push_back(*result);
49 if constexpr (HasShrinkToFit<InputVector>) {
50 output.shrink_to_fit();
51 }
else if constexpr (HasSqueeze<InputVector>) {
57template<
typename Vec,
typename T>
58auto contains(
const Vec &vec,
const T &value)
60 return std::find(std::begin(vec), std::end(vec), value) != std::end(vec);
63template<
typename T,
typename Function>
64auto map(Function mapValue, std::optional<T> &&optValue) -> std::optional<std::invoke_result_t<Function, T &&>>
67 return mapValue(std::move(*optValue));
72template<
typename To,
typename From>
73auto into(std::optional<From> &&value) -> std::optional<To>