std::convertible_to(3)

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

πŸ’– std::convertible_to(3) πŸ’–

okay so this is the std::convertible_to(3) page from the C++ Standard Libary (that spelling is straight from the header, bestie, not me 😭). buckle up, we're talking concepts and conversions and it's gonna be iconic 🫢

✨ NAME ✨

  • std::convertible_to β€” literally std::convertible_to, that's the name, no cap πŸ’…

🌸 Synopsis 🌸

Defined in header <concepts> β€” yes bestie, that exact header πŸŽ€

template< class From, class To >

concept convertible_to =
    std::is_convertible_v<From, To> &&          (since C++20)
    requires {
        static_cast<To>(std::declval<From>());

    };

The concept convertible_to<From, To> says that an expression of the same type and value category as those of std::declval<From>() can be implicitly and explicitly converted to the type To, and the two forms of conversion produce equal results. it's giving "both roads lead to the same slay" ✨

πŸ¦‹ Semantic requirements πŸ¦‹

So convertible_to<From, To> is modeled only if β€” given a function fun of type std::add_rvalue_reference_t<From>() such that the expression fun() is equality-preserving β€” these things are true:

  • Either
    • To is neither an object type nor a reference-to-object type, or
    • static_cast<To>(fun()) is equal to []() -> To { return fun(); }(), and
  • One of the following is true:
    • std::add_rvalue_reference_t<From> is not a reference-to-object type, or
    • std::add_rvalue_reference_t<From> is an rvalue reference to a non-const-qualified type, and the resulting state of the object referenced by fun() is valid but unspecified after either expression above; or
    • the object referred to by fun() is not modified by either expression above.

🌈 Equality preservation 🌈

Expressions declared in requires expressions of the standard library concepts are required to be equality-preserving (except where stated otherwise). that's the rule, bestie, no exceptions unless the page says so πŸ’…

πŸ‘€ See also πŸ‘€

  • is_convertible (C++11) (class template) and is_nothrow_convertible (C++20) β€” checks if a type can be converted to the other type.
std::convertible_to(3) Β· source/version: http://cppreference.com Β· date: 2024.06.10 β€” okay bye bestie, go convert responsibly πŸ’–βœ¨
πŸ“¦ where this page comes from