1
0
Fork 0
mirror of https://github.com/Neargye/magic_enum.git synced 2026-01-10 23:44:29 +00:00

fix clang-format

This commit is contained in:
neargye 2023-05-23 21:12:42 +04:00
parent dd2fb1b9a3
commit 50adc0691e
6 changed files with 133 additions and 142 deletions

View file

@ -1,6 +1,7 @@
// Licensed under the MIT License <http://opensource.org/licenses/MIT>. // Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// Copyright (c) 2019 - 2023 Daniil Goncharov <neargye@gmail.com>. // Copyright (c) 2019 - 2023 Daniil Goncharov <neargye@gmail.com>.
// Copyright (c) 2022 - 2023 Bela Schaum <schaumb@gmail.com>.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal

View file

@ -1,6 +1,7 @@
// Licensed under the MIT License <http://opensource.org/licenses/MIT>. // Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// Copyright (c) 2019 - 2023 Daniil Goncharov <neargye@gmail.com>. // Copyright (c) 2019 - 2023 Daniil Goncharov <neargye@gmail.com>.
// Copyright (c) 2022 - 2023 Bela Schaum <schaumb@gmail.com>.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal

View file

@ -1,6 +1,7 @@
// Licensed under the MIT License <http://opensource.org/licenses/MIT>. // Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// Copyright (c) 2019 - 2023 Daniil Goncharov <neargye@gmail.com>. // Copyright (c) 2019 - 2023 Daniil Goncharov <neargye@gmail.com>.
// Copyright (c) 2022 - 2023 Bela Schaum <schaumb@gmail.com>.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal

View file

@ -1,7 +1,7 @@
// Licensed under the MIT License <http://opensource.org/licenses/MIT>. // Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// Copyright (c) 2019 - 2023 Daniil Goncharov <neargye@gmail.com>. // Copyright (c) 2019 - 2023 Daniil Goncharov <neargye@gmail.com>.
// Copyright (c) 2020 - 2023 Bela Schaum <schaumb@gmail.com>. // Copyright (c) 2022 - 2023 Bela Schaum <schaumb@gmail.com>.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal

View file

@ -10,7 +10,7 @@
// Licensed under the MIT License <http://opensource.org/licenses/MIT>. // Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// Copyright (c) 2019 - 2023 Daniil Goncharov <neargye@gmail.com>. // Copyright (c) 2019 - 2023 Daniil Goncharov <neargye@gmail.com>.
// Copyright (c) 2023 - 2023 Bela Schaum <schaumb@gmail.com>. // Copyright (c) 2022 - 2023 Bela Schaum <schaumb@gmail.com>.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -33,10 +33,10 @@
#ifndef NEARGYE_MAGIC_ENUM_CONTAINERS_HPP #ifndef NEARGYE_MAGIC_ENUM_CONTAINERS_HPP
#define NEARGYE_MAGIC_ENUM_CONTAINERS_HPP #define NEARGYE_MAGIC_ENUM_CONTAINERS_HPP
#include "magic_enum.hpp"
#include <stdexcept> #include <stdexcept>
#include "magic_enum.hpp"
namespace magic_enum::containers { namespace magic_enum::containers {
namespace detail { namespace detail {
@ -111,9 +111,7 @@ constexpr ForwardIt lower_bound(ForwardIt first, ForwardIt last, E &&e, Cmp &&co
template <typename Cmp = std::less<>, typename BidirIt, typename E> template <typename Cmp = std::less<>, typename BidirIt, typename E>
constexpr auto equal_range(BidirIt begin, BidirIt end, E&& e, Cmp&& comp = {}) { constexpr auto equal_range(BidirIt begin, BidirIt end, E&& e, Cmp&& comp = {}) {
const auto first = lower_bound(begin, end, e, comp); const auto first = lower_bound(begin, end, e, comp);
return std::pair{first, lower_bound(std::make_reverse_iterator(end), std::make_reverse_iterator(first), e, [&comp](auto &&lhs, auto &&rhs) { return std::pair{first, lower_bound(std::make_reverse_iterator(end), std::make_reverse_iterator(first), e, [&comp](auto&& lhs, auto&& rhs) { return comp(rhs, lhs); }).base()};
return comp(rhs, lhs);
}).base()};
} }
template <typename E = void, typename Cmp = std::less<E>, typename = void> template <typename E = void, typename Cmp = std::less<E>, typename = void>
@ -480,11 +478,9 @@ class bitset {
std::size_t num_index; std::size_t num_index;
base_type bit_index; base_type bit_index;
constexpr reference_impl(parent_t parent, std::size_t ix) noexcept constexpr reference_impl(parent_t parent, std::size_t ix) noexcept : reference_impl(parent, std::pair{ix / bits_per_base, base_type{1} << (ix % bits_per_base)}) {}
: reference_impl(parent, std::pair{ix / bits_per_base, base_type{1} << (ix % bits_per_base)}) {}
constexpr reference_impl(parent_t parent, std::pair<std::size_t, base_type> ix) noexcept constexpr reference_impl(parent_t parent, std::pair<std::size_t, base_type> ix) noexcept : parent(parent), num_index(std::get<0>(ix)), bit_index(std::get<1>(ix)) {}
: parent(parent), num_index(std::get<0>(ix)), bit_index(std::get<1>(ix)) {}
public: public:
constexpr reference_impl& operator=(bool v) noexcept { constexpr reference_impl& operator=(bool v) noexcept {
@ -580,8 +576,7 @@ public:
} }
} }
} }
template <class V, template <typename V, std::enable_if_t<std::is_same_v<V, E> && magic_enum::detail::subtype_v<V> == magic_enum::detail::enum_subtype::flags, int> = 0>
std::enable_if_t<std::is_same_v<V, E> && magic_enum::detail::subtype_v<V> == magic_enum::detail::enum_subtype::flags, int> = 0>
constexpr explicit bitset(V starter) : a{{}} { constexpr explicit bitset(V starter) : a{{}} {
auto u = enum_underlying(starter); auto u = enum_underlying(starter);
for (E v : enum_values<E>()) { for (E v : enum_values<E>()) {
@ -598,14 +593,14 @@ public:
template <typename Cmp = std::equal_to<>> template <typename Cmp = std::equal_to<>>
constexpr explicit bitset(string_view sv, Cmp&& cmp = {}, char sep = '|') { constexpr explicit bitset(string_view sv, Cmp&& cmp = {}, char sep = '|') {
for (std::size_t to{}; (to = magic_enum::detail::find(sv, sep)) != string_view::npos; sv.remove_prefix(to + 1)) { for (std::size_t to{}; (to = magic_enum::detail::find(sv, sep)) != string_view::npos; sv.remove_prefix(to + 1)) {
if (auto v = magic_enum::enum_cast<E>(sv.substr(0, to), cmp)) { if (auto v = enum_cast<E>(sv.substr(0, to), cmp)) {
set(v); set(v);
} else { } else {
throw std::invalid_argument("enum bitset::constructor: unrecognized enum value in string"); throw std::invalid_argument("enum bitset::constructor: unrecognized enum value in string");
} }
} }
if (!sv.empty()) { if (!sv.empty()) {
if (auto v = magic_enum::enum_cast<E>(sv, cmp)) { if (auto v = enum_cast<E>(sv, cmp)) {
set(v); set(v);
} else { } else {
throw std::invalid_argument("enum bitset::constructor: unrecognized enum value in string"); throw std::invalid_argument("enum bitset::constructor: unrecognized enum value in string");
@ -803,7 +798,7 @@ private:
container_type a; container_type a;
}; };
template <class V, int = 0> template <typename V, int = 0>
explicit bitset(V starter) -> bitset<V>; explicit bitset(V starter) -> bitset<V>;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -850,8 +845,7 @@ public:
insert(e); insert(e);
} }
} }
template <class V, template <typename V, std::enable_if_t<std::is_same_v<V, E> && magic_enum::detail::subtype_v<V> == magic_enum::detail::enum_subtype::flags, int> = 0>
std::enable_if_t<std::is_same_v<V, E> &&magic_enum::detail::subtype_v<V> == magic_enum::detail::enum_subtype::flags, int> = 0>
constexpr explicit set(V starter) { constexpr explicit set(V starter) {
auto u = enum_underlying(starter); auto u = enum_underlying(starter);
for (E v : enum_values<E>()) { for (E v : enum_values<E>()) {
@ -937,10 +931,14 @@ public:
} }
template <typename... Args> template <typename... Args>
constexpr std::pair<iterator, bool> emplace(Args &&... args) noexcept { return insert({std::forward<Args>(args)...}); } constexpr std::pair<iterator, bool> emplace(Args&&... args) noexcept {
return insert({std::forward<Args>(args)...});
}
template <typename... Args> template <typename... Args>
constexpr iterator emplace_hint(const_iterator, Args &&... args) noexcept { return emplace(std::forward<Args>(args)...).first; } constexpr iterator emplace_hint(const_iterator, Args&&... args) noexcept {
return emplace(std::forward<Args>(args)...).first;
}
constexpr iterator erase(const_iterator pos) noexcept { constexpr iterator erase(const_iterator pos) noexcept {
erase(*pos++); erase(*pos++);
@ -1013,9 +1011,7 @@ public:
return count(x) > 0; return count(x) > 0;
} }
[[nodiscard]] constexpr std::pair<const_iterator, const_iterator> equal_range(const key_type &key) const noexcept { [[nodiscard]] constexpr std::pair<const_iterator, const_iterator> equal_range(const key_type& key) const noexcept { return {lower_bound(key), upper_bound(key)}; }
return {lower_bound(key), upper_bound(key)};
}
template <typename K, typename KC = key_compare> template <typename K, typename KC = key_compare>
[[nodiscard]] constexpr std::enable_if_t<detail::is_transparent_v<KC>, std::pair<const_iterator, const_iterator>> equal_range(const K& x) const noexcept { [[nodiscard]] constexpr std::enable_if_t<detail::is_transparent_v<KC>, std::pair<const_iterator, const_iterator>> equal_range(const K& x) const noexcept {
@ -1098,8 +1094,7 @@ private:
std::size_t s{}; std::size_t s{};
}; };
template <typename V, int = 0>
template <class V, int = 0>
explicit set(V starter) -> set<V>; explicit set(V starter) -> set<V>;
} // namespace magic_enum::containers } // namespace magic_enum::containers
@ -1107,50 +1102,42 @@ explicit set(V starter) -> set<V>;
namespace std { namespace std {
template <auto I, typename E, typename V, typename Index> template <auto I, typename E, typename V, typename Index>
constexpr std::enable_if_t<(std::is_integral_v<decltype(I)> && I < magic_enum::enum_count<E>()), V &> constexpr std::enable_if_t<(std::is_integral_v<decltype(I)> && I < magic_enum::enum_count<E>()), V&> get(magic_enum::containers::array<E, V, Index>& a) noexcept {
get(magic_enum::containers::array<E, V, Index> &a) noexcept {
return a.a[I]; return a.a[I];
} }
template <auto I, typename E, typename V, typename Index> template <auto I, typename E, typename V, typename Index>
constexpr std::enable_if_t<(std::is_integral_v<decltype(I)> && I < magic_enum::enum_count<E>()), V &&> constexpr std::enable_if_t<(std::is_integral_v<decltype(I)> && I < magic_enum::enum_count<E>()), V&&> get(magic_enum::containers::array<E, V, Index>&& a) noexcept {
get(magic_enum::containers::array<E, V, Index> &&a) noexcept {
return std::move(a.a[I]); return std::move(a.a[I]);
} }
template <auto I, typename E, typename V, typename Index> template <auto I, typename E, typename V, typename Index>
constexpr std::enable_if_t<(std::is_integral_v<decltype(I)> && I < magic_enum::enum_count<E>()), const V &> constexpr std::enable_if_t<(std::is_integral_v<decltype(I)> && I < magic_enum::enum_count<E>()), const V&> get(const magic_enum::containers::array<E, V, Index>& a) noexcept {
get(const magic_enum::containers::array<E, V, Index> &a) noexcept {
return a.a[I]; return a.a[I];
} }
template <auto I, typename E, typename V, typename Index> template <auto I, typename E, typename V, typename Index>
constexpr std::enable_if_t<(std::is_integral_v<decltype(I)> && I < magic_enum::enum_count<E>()), const V &&> constexpr std::enable_if_t<(std::is_integral_v<decltype(I)> && I < magic_enum::enum_count<E>()), const V&&> get(const magic_enum::containers::array<E, V, Index>&& a) noexcept {
get(const magic_enum::containers::array<E, V, Index> &&a) noexcept {
return std::move(a.a[I]); return std::move(a.a[I]);
} }
template <auto Enum, typename E, typename V, typename Index> template <auto Enum, typename E, typename V, typename Index>
constexpr std::enable_if_t<std::is_same_v<decltype(Enum), E> && magic_enum::enum_contains(Enum), V &> constexpr std::enable_if_t<std::is_same_v<decltype(Enum), E> && magic_enum::enum_contains(Enum), V&> get(magic_enum::containers::array<E, V, Index>& a) noexcept {
get(magic_enum::containers::array<E, V, Index> &a) noexcept {
return a[Enum]; return a[Enum];
} }
template <auto Enum, typename E, typename V, typename Index> template <auto Enum, typename E, typename V, typename Index>
constexpr std::enable_if_t<std::is_same_v<decltype(Enum), E> && magic_enum::enum_contains(Enum), V &&> constexpr std::enable_if_t<std::is_same_v<decltype(Enum), E> && magic_enum::enum_contains(Enum), V&&> get(magic_enum::containers::array<E, V, Index>&& a) noexcept {
get(magic_enum::containers::array<E, V, Index> &&a) noexcept {
return std::move(a[Enum]); return std::move(a[Enum]);
} }
template <auto Enum, typename E, typename V, typename Index> template <auto Enum, typename E, typename V, typename Index>
constexpr std::enable_if_t<std::is_same_v<decltype(Enum), E> && magic_enum::enum_contains(Enum), const V &> constexpr std::enable_if_t<std::is_same_v<decltype(Enum), E> && magic_enum::enum_contains(Enum), const V&> get(const magic_enum::containers::array<E, V, Index>& a) noexcept {
get(const magic_enum::containers::array<E, V, Index> &a) noexcept {
return a[Enum]; return a[Enum];
} }
template <auto Enum, typename E, typename V, typename Index> template <auto Enum, typename E, typename V, typename Index>
constexpr std::enable_if_t<std::is_same_v<decltype(Enum), E> && magic_enum::enum_contains(Enum), const V &&> constexpr std::enable_if_t<std::is_same_v<decltype(Enum), E> && magic_enum::enum_contains(Enum), const V&&> get(const magic_enum::containers::array<E, V, Index>&& a) noexcept {
get(const magic_enum::containers::array<E, V, Index> &&a) noexcept {
return std::move(a[Enum]); return std::move(a[Enum]);
} }

View file

@ -1,6 +1,7 @@
// Licensed under the MIT License <http://opensource.org/licenses/MIT>. // Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// Copyright (c) 2019 - 2023 Daniil Goncharov <neargye@gmail.com>. // Copyright (c) 2019 - 2023 Daniil Goncharov <neargye@gmail.com>.
// Copyright (c) 2022 - 2023 Bela Schaum <schaumb@gmail.com>.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal