std::experi...ect::Object(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– NAME πŸ’–

okay so bestie, welcome to the std::experi...ect::Object(3) page from the C++ Standard Libary manual. (Yes, β€œLibary” β€” we keep the typo, she’s iconic πŸ’….) The NAME line is literally std::experimental::reflect::Object - std::experimental::reflect::Object, and the whole page is about std::experimental::reflect::Object in the reflection TS. No cap, it’s giving β€œconcept girl” energy. ✨

✨ Synopsis ✨

here’s the exact synopsis, bestie β€” don’t let the spacing gaslight you:

          Defined in header <experimental/reflect>
          template< class T >                       (reflection TS)
          concept Object = /* see below */;

Quick vibe check: the Object concept is satisfied if and only if T is a meta-object type. periodt. πŸ’–

🌸 Example 🌸

this example is doing the most in the cutest way: it defines meta_t, operator==, operator!=, and meta, then runs a static_assert. Copy it exactly, including the slightly feral line break in the static_assert β€” it’s part of the example πŸ™ˆ:

        // Run this code

        #include <experimental/reflect>

        namespace reflect = std::experimental::reflect;

        template<reflect::Object M>
        struct meta_t {
            template<reflect::Object M1>
            friend constexpr bool operator==(meta_t, meta_t<M1>) noexcept
            {
                return reflect::reflects_same_v<M, M1>;
            }
            template<reflect::Object M1>
            friend constexpr bool operator!=(meta_t, meta_t<M1>) noexcept
            {
                return !reflect::reflects_same_v<M, M1>;
            }
        };

        template<reflect::Object M>
        constexpr meta_t<M> meta{};

        int main()
        {
            static_assert(meta<reflexpr(int)> == meta<reflexpr(signed int)>,
       "");
            // meta<int>; // error: int is not a meta-object type
        }

and that’s the whole page, bestie β€” short, sweet, and fully meta. πŸ¦‹


cute sign-off time πŸŽ€: source/version is http://cppreference.com, date is 2024.06.10, and the page is std::experi...ect::Object(3). mwah πŸ’‹

πŸ“¦ where this page comes from