std::is_final(3)

πŸ“¦
version 2024.07.05 Β· 4 versions
, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– std::is_final(3) β€” C++ Standard Library, bestie πŸŽ€βœ¨

Okay so this is the manual page for std::is_final in the C++ Standard Library, and it’s giving β€œtiny trait, huge main character energy.” πŸ’…

🌸 NAME 🌸

std::is_final β€” literally the trait that checks whether a type is final. That’s the whole name, no cap. πŸ’–

✨ Synopsis ✨

Defined in header <type_traits>.

template< class T >              (since C++14)
struct is_final;

std::is_final is a UnaryTypeTrait.

If T is a final class, it provides the member constant value equal true. For any other type, value is false.

⚠️ If T is an incomplete class type, the behavior is undefined. Not a vibe. πŸ’€
⚠️ If the program adds specializations for std::is_final or std::is_final_v (since C++17), the behavior is undefined. Do not do this, bestie. πŸ™ˆ

🧚 Template parameters 🧚

  • T β€” a type to check.

🌈 Helper variable template 🌈

template< class T >                                     (since C++17)
inline constexpr bool is_final_v = is_final<T>::value;

🧬 Inherited from std::integral_constant 🧬

This trait inherits from std::integral_constant, iykyk. ✨

πŸ‘‘ Member constants πŸ‘‘

  • value β€” true if T is a final class type, false otherwise. [static] (public static member constant).

πŸ’… Member functions πŸ’…

  • operator bool β€” converts the object to bool, returns value (public member function).
  • operator() β€” returns value (C++14) (public member function).

πŸ¦‹ Member types πŸ¦‹

  • value_type β€” bool.
  • type β€” std::integral_constant<bool, value>.

πŸ“ Notes πŸ“

std::is_final is introduced by the resolution of LWG issue 2112.

A union can be declared final (and std::is_final will detect that), even though unions cannot be used as bases in any case. That’s right, bestie: final union? Iconic. 🫢

Feature-test macro vibes:

  • __cpp_lib_is_final β€” value 201402L, std (C++14), feature std::is_final.

πŸ“ Example πŸ“

// Run this code

#include <type_traits>

class A {};
static_assert(std::is_final_v<A> == false);

class B final {};
static_assert(std::is_final_v<B> == true);

union U final
{
    int x;
    double d;
};
static_assert(std::is_final_v<U> == true);

int main()
{
}

🌸 See also 🌸

  • is_class β€” checks if a type is a non-union class type (C++11) (class template).
  • is_polymorphic β€” checks if a type is a polymorphic class type (C++11) (class template).

πŸ’Œ source/version/date: http://cppreference.com Β· 2024.06.10 Β· this manual page is std::is_final(3). mwah πŸ’‹

πŸ“¦ where this page comes from