std::is_scoped_enum(3)
π std::is_scoped_enum(3) π
okay so this page is from the C++ Standard Libary (yes bestie, thatβs literally how the manual name is spelled up top β Iβm not fixing it π), and itβs giving βis this type a scoped enum or not?β realness. Letβs get into it π
π NAME π
std::is_scoped_enum β std::is_scoped_enum. Thatβs the name, periodt. β¨
πΈ Synopsis πΈ
Defined in header <type_traits>:
template< class T > (since C++23)
struct is_scoped_enum;
std::is_scoped_enum is a UnaryTypeTrait.
It checks whether T is a scoped enumeration type. It provides the member constant value which is equal to true if T is a scoped enumeration type. Otherwise, value is equal to false. π¦
β οΈ If the program adds specializations forstd::is_scoped_enumorstd::is_scoped_enum_v, the behavior is undefined. Like, do not do that. Undefined behavior is not the vibe. π
π Template parameters π
Tβ a type to check.
β¨ Helper variable template β¨
Since C++23:
template< class T >
inline constexpr bool is_scoped_enum_v = is_scoped_enum<T>::value;
π«Ά Inherited from std::integral_constant π«Ά
This trait inherits from std::integral_constant, so itβs got that integral-constant main character energy. π
π Member constants π
valueβtrueifTis a scoped enumeration type,falseotherwise.[static](public static member constant) β¨
π Member functions π
operator boolβ converts the object tobool, returnsvalue(public member function).operator()β returnsvalue(C++14) (public member function).
π Member types π
value_typeβbooltypeβstd::integral_constant<bool, value>
π§ Notes π§
Feature-test macro check, iykyk:
__cpp_lib_is_scoped_enumβ value202011Lβ std(C++23)β featurestd::is_scoped_enum
π₯ Possible implementation π₯
template<typename E>
struct is_scoped_enum : std::bool_constant<requires
{
requires std::is_enum_v<E>;
requires !std::is_convertible_v<E, std::underlying_type_t<E>>;
}>
{};
π Example π
// Run this code
#include <type_traits>
class A {};
enum E {};
enum struct Es { oz };
enum class Ec : int {};
int main()
{
static_assert(std::is_scoped_enum_v<A> == false);
static_assert(std::is_scoped_enum_v<E> == false);
static_assert(std::is_scoped_enum_v<Es> == true);
static_assert(std::is_scoped_enum_v<Ec> == true);
static_assert(std::is_scoped_enum_v<int> == false);
}
π See also π
is_integralβ checks if a type is an integral type (C++11) (class template)is_arithmeticβ checks if a type is an arithmetic type (C++11) (class template)is_scalarβ checks if a type is a scalar type (C++11) (class template)is_enumβ checks if a type is an enumeration type (C++11) (class template)
okay thatβs the whole page, bestie. source/version/date vibe: http://cppreference.com Β· 2024.06.10 Β· std::is_scoped_enum(3) β mwah πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms