remove enum.hpp library usage

This commit is contained in:
BlackMATov
2022-08-19 02:26:06 +07:00
parent 83fd973f55
commit 35c312ed4a
17 changed files with 184 additions and 1787 deletions

3
.gitmodules vendored
View File

@@ -1,6 +1,3 @@
[submodule "vendors/enum.hpp"]
path = vendors/enum.hpp
url = https://github.com/BlackMATov/enum.hpp
[submodule "vendors/doctest"] [submodule "vendors/doctest"]
path = vendors/doctest path = vendors/doctest
url = https://github.com/onqtam/doctest url = https://github.com/onqtam/doctest

View File

@@ -33,9 +33,8 @@
#include <variant> #include <variant>
#include <vector> #include <vector>
#include "meta_base/bitflags.hpp"
#include "meta_base/cvref_traits.hpp" #include "meta_base/cvref_traits.hpp"
#include "meta_base/enum_bitflags.hpp"
#include "meta_base/enum.hpp"
#include "meta_base/fixed_function.hpp" #include "meta_base/fixed_function.hpp"
#include "meta_base/hash_combiner.hpp" #include "meta_base/hash_combiner.hpp"
#include "meta_base/noncopyable.hpp" #include "meta_base/noncopyable.hpp"
@@ -63,8 +62,6 @@ namespace meta_hpp
using detail::type_id; using detail::type_id;
using detail::type_kind; using detail::type_kind;
using detail::type_list; using detail::type_list;
using enum_hpp::bitflags::bitflags;
} }
namespace meta_hpp namespace meta_hpp

View File

@@ -0,0 +1,172 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/meta.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2021-2022, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#pragma once
#include <functional>
#include <type_traits>
#include <utility>
namespace meta_hpp::detail
{
template < typename Enum >
class bitflags final {
static_assert(std::is_enum_v<Enum>);
public:
using enum_type = Enum;
using underlying_type = std::underlying_type_t<Enum>;
bitflags() = default;
bitflags(const bitflags&) = default;
bitflags& operator=(const bitflags&) = default;
bitflags(bitflags&&) noexcept = default;
bitflags& operator=(bitflags&&) noexcept = default;
~bitflags() = default;
constexpr bitflags(enum_type flags)
: flags_(static_cast<underlying_type>(flags)) {}
constexpr explicit bitflags(underlying_type flags)
: flags_(flags) {}
constexpr void swap(bitflags& other) noexcept {
using std::swap;
swap(flags_, other.flags_);
}
constexpr explicit operator bool() const noexcept {
return !!flags_;
}
constexpr underlying_type as_raw() const noexcept {
return flags_;
}
constexpr enum_type as_enum() const noexcept {
return static_cast<enum_type>(flags_);
}
constexpr bool has(bitflags flags) const noexcept {
return flags.flags_ == (flags_ & flags.flags_);
}
constexpr bitflags& set(bitflags flags) noexcept {
flags_ |= flags.flags_;
return *this;
}
constexpr bitflags& toggle(bitflags flags) noexcept {
flags_ ^= flags.flags_;
return *this;
}
constexpr bitflags& clear(bitflags flags) noexcept {
flags_ &= ~flags.flags_;
return *this;
}
private:
underlying_type flags_{};
};
template < typename Enum >
constexpr void swap(bitflags<Enum>& l, bitflags<Enum>& r) noexcept {
l.swap(r);
}
}
namespace std
{
template < typename Enum >
struct hash<meta_hpp::detail::bitflags<Enum>> {
size_t operator()(meta_hpp::detail::bitflags<Enum> bf) const noexcept {
return hash<Enum>{}(bf.as_enum());
}
};
}
namespace meta_hpp::detail
{
#define META_HPP_DEFINE_BINARY_OPERATOR(op)\
template < typename Enum >\
constexpr bool operator op(Enum l, bitflags<Enum> r) noexcept {\
return l op r.as_enum();\
}\
template < typename Enum >\
constexpr bool operator op(bitflags<Enum> l, Enum r) noexcept {\
return l.as_enum() op r;\
}\
template < typename Enum >\
constexpr bool operator op(std::underlying_type_t<Enum> l, bitflags<Enum> r) noexcept {\
return l op r.as_raw();\
}\
template < typename Enum >\
constexpr bool operator op(bitflags<Enum> l, std::underlying_type_t<Enum> r) noexcept {\
return l.as_raw() op r;\
}\
template < typename Enum >\
constexpr bool operator op(bitflags<Enum> l, bitflags<Enum> r) noexcept {\
return l.as_raw() op r.as_raw();\
}
META_HPP_DEFINE_BINARY_OPERATOR(<)
META_HPP_DEFINE_BINARY_OPERATOR(>)
META_HPP_DEFINE_BINARY_OPERATOR(<=)
META_HPP_DEFINE_BINARY_OPERATOR(>=)
META_HPP_DEFINE_BINARY_OPERATOR(==)
META_HPP_DEFINE_BINARY_OPERATOR(!=)
#undef META_HPP_DEFINE_BINARY_OPERATOR
}
namespace meta_hpp::detail
{
template < typename Enum >
constexpr bitflags<Enum> operator~(bitflags<Enum> l) noexcept {
return static_cast<Enum>(~l.as_raw());
}
#define META_HPP_DEFINE_BINARY_OPERATOR(op)\
template < typename Enum >\
constexpr bitflags<Enum> operator op (Enum l, bitflags<Enum> r) noexcept {\
return bitflags{l} op r;\
}\
template < typename Enum >\
constexpr bitflags<Enum> operator op (bitflags<Enum> l, Enum r) noexcept {\
return l op bitflags<Enum>{r};\
}\
template < typename Enum >\
constexpr bitflags<Enum> operator op (bitflags<Enum> l, bitflags<Enum> r) noexcept {\
return static_cast<Enum>(l.as_raw() op r.as_raw());\
}\
template < typename Enum >\
constexpr bitflags<Enum>& operator op##= (bitflags<Enum>& l, Enum r) noexcept {\
return l = l op bitflags<Enum>{r};\
}\
template < typename Enum >\
constexpr bitflags<Enum>& operator op##= (bitflags<Enum>& l, bitflags<Enum> r) noexcept {\
return l = l op r;\
}
META_HPP_DEFINE_BINARY_OPERATOR(|)
META_HPP_DEFINE_BINARY_OPERATOR(&)
META_HPP_DEFINE_BINARY_OPERATOR(^)
#undef META_HPP_DEFINE_BINARY_OPERATOR
}
//
// META_HPP_BITFLAGS_OPERATORS_DECL
//
#define META_HPP_BITFLAGS_OPERATORS_DECL(Enum)\
constexpr ::meta_hpp::detail::bitflags<Enum> operator~ [[maybe_unused]] (Enum l) noexcept {\
return ~::meta_hpp::detail::bitflags<Enum>(l);\
}\
constexpr ::meta_hpp::detail::bitflags<Enum> operator| [[maybe_unused]] (Enum l, Enum r) noexcept {\
return ::meta_hpp::detail::bitflags<Enum>(l) | ::meta_hpp::detail::bitflags<Enum>(r);\
}\
constexpr ::meta_hpp::detail::bitflags<Enum> operator& [[maybe_unused]] (Enum l, Enum r) noexcept {\
return ::meta_hpp::detail::bitflags<Enum>(l) & ::meta_hpp::detail::bitflags<Enum>(r);\
}\
constexpr ::meta_hpp::detail::bitflags<Enum> operator^ [[maybe_unused]] (Enum l, Enum r) noexcept {\
return ::meta_hpp::detail::bitflags<Enum>(l) ^ ::meta_hpp::detail::bitflags<Enum>(r);\
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,332 +0,0 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/enum.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#pragma once
#include <functional>
#include <type_traits>
#include <utility>
namespace enum_hpp::bitflags
{
template < typename Enum >
class bitflags final {
static_assert(std::is_enum_v<Enum>);
public:
using enum_type = Enum;
using underlying_type = std::underlying_type_t<Enum>;
bitflags() = default;
bitflags(const bitflags&) = default;
bitflags& operator=(const bitflags&) = default;
bitflags(bitflags&&) noexcept = default;
bitflags& operator=(bitflags&&) noexcept = default;
~bitflags() = default;
constexpr bitflags(enum_type flags)
: flags_(static_cast<underlying_type>(flags)) {}
constexpr explicit bitflags(underlying_type flags)
: flags_(flags) {}
constexpr void swap(bitflags& other) noexcept {
using std::swap;
swap(flags_, other.flags_);
}
constexpr explicit operator bool() const noexcept {
return !!flags_;
}
constexpr underlying_type as_raw() const noexcept {
return flags_;
}
constexpr enum_type as_enum() const noexcept {
return static_cast<enum_type>(flags_);
}
constexpr bool has(bitflags flags) const noexcept {
return flags.flags_ == (flags_ & flags.flags_);
}
constexpr bitflags& set(bitflags flags) noexcept {
flags_ |= flags.flags_;
return *this;
}
constexpr bitflags& toggle(bitflags flags) noexcept {
flags_ ^= flags.flags_;
return *this;
}
constexpr bitflags& clear(bitflags flags) noexcept {
flags_ &= ~flags.flags_;
return *this;
}
private:
underlying_type flags_{};
};
template < typename Enum >
constexpr void swap(bitflags<Enum>& l, bitflags<Enum>& r) noexcept {
l.swap(r);
}
}
namespace std
{
template < typename Enum >
struct hash<enum_hpp::bitflags::bitflags<Enum>> {
size_t operator()(enum_hpp::bitflags::bitflags<Enum> bf) const noexcept {
return hash<Enum>{}(bf.as_enum());
}
};
}
namespace enum_hpp::bitflags
{
#define ENUM_HPP_DEFINE_BINARY_OPERATOR(op)\
template < typename Enum >\
constexpr bool operator op(Enum l, bitflags<Enum> r) noexcept {\
return l op r.as_enum();\
}\
template < typename Enum >\
constexpr bool operator op(bitflags<Enum> l, Enum r) noexcept {\
return l.as_enum() op r;\
}\
template < typename Enum >\
constexpr bool operator op(std::underlying_type_t<Enum> l, bitflags<Enum> r) noexcept {\
return l op r.as_raw();\
}\
template < typename Enum >\
constexpr bool operator op(bitflags<Enum> l, std::underlying_type_t<Enum> r) noexcept {\
return l.as_raw() op r;\
}\
template < typename Enum >\
constexpr bool operator op(bitflags<Enum> l, bitflags<Enum> r) noexcept {\
return l.as_raw() op r.as_raw();\
}
ENUM_HPP_DEFINE_BINARY_OPERATOR(<)
ENUM_HPP_DEFINE_BINARY_OPERATOR(>)
ENUM_HPP_DEFINE_BINARY_OPERATOR(<=)
ENUM_HPP_DEFINE_BINARY_OPERATOR(>=)
ENUM_HPP_DEFINE_BINARY_OPERATOR(==)
ENUM_HPP_DEFINE_BINARY_OPERATOR(!=)
#undef ENUM_HPP_DEFINE_BINARY_OPERATOR
}
namespace enum_hpp::bitflags
{
template < typename Enum >
constexpr bitflags<Enum> operator~(bitflags<Enum> l) noexcept {
return static_cast<Enum>(~l.as_raw());
}
#define ENUM_HPP_DEFINE_BINARY_OPERATOR(op)\
template < typename Enum >\
constexpr bitflags<Enum> operator op (Enum l, bitflags<Enum> r) noexcept {\
return bitflags{l} op r;\
}\
template < typename Enum >\
constexpr bitflags<Enum> operator op (bitflags<Enum> l, Enum r) noexcept {\
return l op bitflags<Enum>{r};\
}\
template < typename Enum >\
constexpr bitflags<Enum> operator op (bitflags<Enum> l, bitflags<Enum> r) noexcept {\
return static_cast<Enum>(l.as_raw() op r.as_raw());\
}\
template < typename Enum >\
constexpr bitflags<Enum>& operator op##= (bitflags<Enum>& l, Enum r) noexcept {\
return l = l op bitflags<Enum>{r};\
}\
template < typename Enum >\
constexpr bitflags<Enum>& operator op##= (bitflags<Enum>& l, bitflags<Enum> r) noexcept {\
return l = l op r;\
}
ENUM_HPP_DEFINE_BINARY_OPERATOR(|)
ENUM_HPP_DEFINE_BINARY_OPERATOR(&)
ENUM_HPP_DEFINE_BINARY_OPERATOR(^)
#undef ENUM_HPP_DEFINE_BINARY_OPERATOR
}
namespace enum_hpp::bitflags
{
//
// any
//
template < typename Enum
, std::enable_if_t<std::is_enum_v<Enum>, int> = 0 >
constexpr bool any(Enum flags) noexcept {
return any(bitflags{flags});
}
template < typename Enum >
constexpr bool any(bitflags<Enum> flags) noexcept {
return 0 != flags.as_raw();
}
//
// none
//
template < typename Enum
, std::enable_if_t<std::is_enum_v<Enum>, int> = 0 >
constexpr bool none(Enum flags) noexcept {
return none(bitflags{flags});
}
template < typename Enum >
constexpr bool none(bitflags<Enum> flags) noexcept {
return 0 == flags.as_raw();
}
//
// all_of
//
template < typename Enum
, std::enable_if_t<std::is_enum_v<Enum>, int> = 0 >
constexpr bool all_of(Enum flags, Enum mask) noexcept {
return all_of(bitflags{flags}, bitflags{mask});
}
template < typename Enum >
constexpr bool all_of(Enum flags, bitflags<Enum> mask) noexcept {
return all_of(bitflags{flags}, mask);
}
template < typename Enum >
constexpr bool all_of(bitflags<Enum> flags, Enum mask) noexcept {
return all_of(flags, bitflags{mask});
}
template < typename Enum >
constexpr bool all_of(bitflags<Enum> flags, bitflags<Enum> mask) noexcept {
return (flags.as_raw() & mask.as_raw()) == mask.as_raw();
}
//
// any_of
//
template < typename Enum
, std::enable_if_t<std::is_enum_v<Enum>, int> = 0 >
constexpr bool any_of(Enum flags, Enum mask) noexcept {
return any_of(bitflags{flags}, bitflags{mask});
}
template < typename Enum >
constexpr bool any_of(Enum flags, bitflags<Enum> mask) noexcept {
return any_of(bitflags{flags}, mask);
}
template < typename Enum >
constexpr bool any_of(bitflags<Enum> flags, Enum mask) noexcept {
return any_of(flags, bitflags{mask});
}
template < typename Enum >
constexpr bool any_of(bitflags<Enum> flags, bitflags<Enum> mask) noexcept {
return mask.as_raw() == 0
|| (flags.as_raw() & mask.as_raw()) != 0;
}
//
// none_of
//
template < typename Enum
, std::enable_if_t<std::is_enum_v<Enum>, int> = 0 >
constexpr bool none_of(Enum flags, Enum mask) noexcept {
return none_of(bitflags{flags}, bitflags{mask});
}
template < typename Enum >
constexpr bool none_of(Enum flags, bitflags<Enum> mask) noexcept {
return none_of(bitflags{flags}, mask);
}
template < typename Enum >
constexpr bool none_of(bitflags<Enum> flags, Enum mask) noexcept {
return none_of(flags, bitflags{mask});
}
template < typename Enum >
constexpr bool none_of(bitflags<Enum> flags, bitflags<Enum> mask) noexcept {
return mask.as_raw() != 0
&& (flags.as_raw() & mask.as_raw()) == 0;
}
//
// any_except
//
template < typename Enum
, std::enable_if_t<std::is_enum_v<Enum>, int> = 0 >
constexpr bool any_except(Enum flags, Enum mask) noexcept {
return any_except(bitflags{flags}, bitflags{mask});
}
template < typename Enum >
constexpr bool any_except(Enum flags, bitflags<Enum> mask) noexcept {
return any_except(bitflags{flags}, mask);
}
template < typename Enum >
constexpr bool any_except(bitflags<Enum> flags, Enum mask) noexcept {
return any_except(flags, bitflags{mask});
}
template < typename Enum >
constexpr bool any_except(bitflags<Enum> flags, bitflags<Enum> mask) noexcept {
return any_of(flags, ~mask);
}
//
// none_except
//
template < typename Enum
, std::enable_if_t<std::is_enum_v<Enum>, int> = 0 >
constexpr bool none_except(Enum flags, Enum mask) noexcept {
return none_except(bitflags{flags}, bitflags{mask});
}
template < typename Enum >
constexpr bool none_except(Enum flags, bitflags<Enum> mask) noexcept {
return none_except(bitflags{flags}, mask);
}
template < typename Enum >
constexpr bool none_except(bitflags<Enum> flags, Enum mask) noexcept {
return none_except(flags, bitflags{mask});
}
template < typename Enum >
constexpr bool none_except(bitflags<Enum> flags, bitflags<Enum> mask) noexcept {
return none_of(flags, ~mask);
}
}
//
// ENUM_HPP_OPERATORS_DECL
//
#define ENUM_HPP_OPERATORS_DECL(Enum)\
constexpr ::enum_hpp::bitflags::bitflags<Enum> operator~ [[maybe_unused]] (Enum l) noexcept {\
return ~::enum_hpp::bitflags::bitflags<Enum>(l);\
}\
constexpr ::enum_hpp::bitflags::bitflags<Enum> operator| [[maybe_unused]] (Enum l, Enum r) noexcept {\
return ::enum_hpp::bitflags::bitflags<Enum>(l) | ::enum_hpp::bitflags::bitflags<Enum>(r);\
}\
constexpr ::enum_hpp::bitflags::bitflags<Enum> operator& [[maybe_unused]] (Enum l, Enum r) noexcept {\
return ::enum_hpp::bitflags::bitflags<Enum>(l) & ::enum_hpp::bitflags::bitflags<Enum>(r);\
}\
constexpr ::enum_hpp::bitflags::bitflags<Enum> operator^ [[maybe_unused]] (Enum l, Enum r) noexcept {\
return ::enum_hpp::bitflags::bitflags<Enum>(l) ^ ::enum_hpp::bitflags::bitflags<Enum>(r);\
}

View File

@@ -15,7 +15,7 @@ namespace meta_hpp::detail
is_unbounded = 1 << 1, is_unbounded = 1 << 1,
}; };
ENUM_HPP_OPERATORS_DECL(array_flags) META_HPP_BITFLAGS_OPERATORS_DECL(array_flags)
using array_bitflags = bitflags<array_flags>; using array_bitflags = bitflags<array_flags>;
} }

View File

@@ -18,7 +18,7 @@ namespace meta_hpp::detail
is_template_instantiation = 1 << 4, is_template_instantiation = 1 << 4,
}; };
ENUM_HPP_OPERATORS_DECL(class_flags) META_HPP_BITFLAGS_OPERATORS_DECL(class_flags)
using class_bitflags = bitflags<class_flags>; using class_bitflags = bitflags<class_flags>;
} }

View File

@@ -14,7 +14,7 @@ namespace meta_hpp::detail
is_noexcept = 1 << 0, is_noexcept = 1 << 0,
}; };
ENUM_HPP_OPERATORS_DECL(constructor_flags) META_HPP_BITFLAGS_OPERATORS_DECL(constructor_flags)
using constructor_bitflags = bitflags<constructor_flags>; using constructor_bitflags = bitflags<constructor_flags>;
} }

View File

@@ -14,7 +14,7 @@ namespace meta_hpp::detail
is_noexcept = 1 << 0, is_noexcept = 1 << 0,
}; };
ENUM_HPP_OPERATORS_DECL(destructor_flags) META_HPP_BITFLAGS_OPERATORS_DECL(destructor_flags)
using destructor_bitflags = bitflags<destructor_flags>; using destructor_bitflags = bitflags<destructor_flags>;
} }

View File

@@ -14,7 +14,7 @@ namespace meta_hpp::detail
is_scoped = 1 << 0, is_scoped = 1 << 0,
}; };
ENUM_HPP_OPERATORS_DECL(enum_flags) META_HPP_BITFLAGS_OPERATORS_DECL(enum_flags)
using enum_bitflags = bitflags<enum_flags>; using enum_bitflags = bitflags<enum_flags>;
} }

View File

@@ -14,7 +14,7 @@ namespace meta_hpp::detail
is_noexcept = 1 << 0, is_noexcept = 1 << 0,
}; };
ENUM_HPP_OPERATORS_DECL(function_flags) META_HPP_BITFLAGS_OPERATORS_DECL(function_flags)
using function_bitflags = bitflags<function_flags>; using function_bitflags = bitflags<function_flags>;
} }

View File

@@ -14,7 +14,7 @@ namespace meta_hpp::detail
is_readonly = 1 << 0, is_readonly = 1 << 0,
}; };
ENUM_HPP_OPERATORS_DECL(member_flags) META_HPP_BITFLAGS_OPERATORS_DECL(member_flags)
using member_bitflags = bitflags<member_flags>; using member_bitflags = bitflags<member_flags>;
} }

View File

@@ -17,7 +17,7 @@ namespace meta_hpp::detail
is_rvalue_qualified = 1 << 3, is_rvalue_qualified = 1 << 3,
}; };
ENUM_HPP_OPERATORS_DECL(method_flags) META_HPP_BITFLAGS_OPERATORS_DECL(method_flags)
using method_bitflags = bitflags<method_flags>; using method_bitflags = bitflags<method_flags>;
} }

View File

@@ -17,7 +17,7 @@ namespace meta_hpp::detail
is_floating_point = 1 << 3, is_floating_point = 1 << 3,
}; };
ENUM_HPP_OPERATORS_DECL(number_flags) META_HPP_BITFLAGS_OPERATORS_DECL(number_flags)
using number_bitflags = bitflags<number_flags>; using number_bitflags = bitflags<number_flags>;
} }

View File

@@ -14,7 +14,7 @@ namespace meta_hpp::detail
is_readonly = 1 << 0, is_readonly = 1 << 0,
}; };
ENUM_HPP_OPERATORS_DECL(pointer_flags) META_HPP_BITFLAGS_OPERATORS_DECL(pointer_flags)
using pointer_bitflags = bitflags<pointer_flags>; using pointer_bitflags = bitflags<pointer_flags>;
} }

View File

@@ -16,7 +16,7 @@ namespace meta_hpp::detail
is_rvalue = 1 << 2, is_rvalue = 1 << 2,
}; };
ENUM_HPP_OPERATORS_DECL(reference_flags) META_HPP_BITFLAGS_OPERATORS_DECL(reference_flags)
using reference_bitflags = bitflags<reference_flags>; using reference_bitflags = bitflags<reference_flags>;
} }

1
vendors/enum.hpp vendored

Submodule vendors/enum.hpp deleted from 2917a832db