From 399f38f2ae6481aee9d7b7a3a7ad436b127dd0bd Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sun, 19 Jul 2026 17:54:35 +0200 Subject: kstd: move bitfiled_enum header --- libs/acpi/acpi/data/madt.hpp | 4 +-- libs/kstd/kstd.dox | 7 ---- libs/kstd/kstd/bitfield_enum.hpp | 68 ++++++++++++++++++++++++++++++++++++ libs/kstd/kstd/ext/bitfield_enum.hpp | 65 ---------------------------------- 4 files changed, 70 insertions(+), 74 deletions(-) create mode 100644 libs/kstd/kstd/bitfield_enum.hpp delete mode 100644 libs/kstd/kstd/ext/bitfield_enum.hpp (limited to 'libs') diff --git a/libs/acpi/acpi/data/madt.hpp b/libs/acpi/acpi/data/madt.hpp index 4d992613..2bff7470 100644 --- a/libs/acpi/acpi/data/madt.hpp +++ b/libs/acpi/acpi/data/madt.hpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include @@ -110,7 +110,7 @@ namespace acpi } // namespace acpi template<> -struct kstd::ext::is_bitfield_enum : std::true_type +struct kstd::is_bitfield_enum : std::true_type { }; diff --git a/libs/kstd/kstd.dox b/libs/kstd/kstd.dox index 5920a3cb..39a2d05e 100644 --- a/libs/kstd/kstd.dox +++ b/libs/kstd/kstd.dox @@ -5,10 +5,3 @@ //! freestanding environment, since it relies on operating system support (e.g. memory allocation). The implementations //! found here, aim to be reasonably close to the specifications found in the C++ language standard (ISO14482). //! However, some differences exists, for example the lack of exceptions. - -//! @namespace kstd::ext -//! Extensions to the Standard Library. -//! -//! This namespace includes custom extensions to what is defined for the C++ Standard Library. These extensions not -//! portable per-se, since they are not implemented by other Standard Library implementations. Whenever possible, -//! Standard Library conformant types, functions, etc. should be used throughout the TeachOS codebase. diff --git a/libs/kstd/kstd/bitfield_enum.hpp b/libs/kstd/kstd/bitfield_enum.hpp new file mode 100644 index 00000000..047052e4 --- /dev/null +++ b/libs/kstd/kstd/bitfield_enum.hpp @@ -0,0 +1,68 @@ +#ifndef KSTD_EXT_BITFIELD_ENUM_HPP +#define KSTD_EXT_BITFIELD_ENUM_HPP + +#include +#include +#include + +namespace kstd +{ + + template + requires std::is_enum_v + struct is_bitfield_enum : std::false_type + { + }; + + //! @concept Specifies that an enum is to be used to define bits in a bitfield. + template + concept bitfield_enum = is_bitfield_enum::value; + +}; // namespace kstd + +template +constexpr auto operator|(EnumType lhs, EnumType rhs) -> EnumType +{ + return std::bit_cast( + static_cast>(std::to_underlying(lhs) | std::to_underlying(rhs))); +} + +template +constexpr auto operator|=(EnumType & lhs, EnumType rhs) -> EnumType & +{ + return lhs = lhs | rhs; +} + +template +constexpr auto operator&(EnumType lhs, EnumType rhs) -> EnumType +{ + return std::bit_cast( + static_cast>(std::to_underlying(lhs) & std::to_underlying(rhs))); +} + +template +constexpr auto operator&=(EnumType & lhs, EnumType rhs) -> EnumType & +{ + return lhs = lhs & rhs; +} + +template +constexpr auto operator^(EnumType lhs, EnumType rhs) -> EnumType +{ + return std::bit_cast( + static_cast>(std::to_underlying(lhs) ^ std::to_underlying(rhs))); +} + +template +constexpr auto operator^=(EnumType & lhs, EnumType rhs) -> EnumType & +{ + return lhs = lhs ^ rhs; +} + +template +constexpr auto operator~(EnumType lhs) -> EnumType +{ + return std::bit_cast(static_cast>(~std::to_underlying(lhs))); +} + +#endif \ No newline at end of file diff --git a/libs/kstd/kstd/ext/bitfield_enum.hpp b/libs/kstd/kstd/ext/bitfield_enum.hpp deleted file mode 100644 index 80fe9d29..00000000 --- a/libs/kstd/kstd/ext/bitfield_enum.hpp +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef KSTD_EXT_BITFIELD_ENUM_HPP -#define KSTD_EXT_BITFIELD_ENUM_HPP - -#include -#include -#include - -namespace kstd::ext -{ - - template - requires std::is_enum_v - struct is_bitfield_enum : std::false_type - { - }; - - //! @concept Specifies that an enum is to be used to define bits in a bitfield. - template - concept bitfield_enum = is_bitfield_enum::value; - -}; // namespace kstd::ext - -template -constexpr auto operator|(EnumType lhs, EnumType rhs) -> EnumType -{ - return std::bit_cast(std::to_underlying(lhs) | std::to_underlying(rhs)); -} - -template -constexpr auto operator|=(EnumType & lhs, EnumType rhs) -> EnumType & -{ - return lhs = lhs | rhs; -} - -template -constexpr auto operator&(EnumType lhs, EnumType rhs) -> EnumType -{ - return std::bit_cast(std::to_underlying(lhs) & std::to_underlying(rhs)); -} - -template -constexpr auto operator&=(EnumType & lhs, EnumType rhs) -> EnumType & -{ - return lhs = lhs & rhs; -} - -template -constexpr auto operator^(EnumType lhs, EnumType rhs) -> EnumType -{ - return std::bit_cast(std::to_underlying(lhs) ^ std::to_underlying(rhs)); -} - -template -constexpr auto operator^=(EnumType & lhs, EnumType rhs) -> EnumType & -{ - return lhs = lhs ^ rhs; -} - -template -constexpr auto operator~(EnumType lhs) -> EnumType -{ - return std::bit_cast(~std::to_underlying(lhs)); -} - -#endif \ No newline at end of file -- cgit v1.2.3