Last active
May 10, 2026 00:46
-
-
Save Eczbek/9ef572fbfc3ae00bd6ee11f1b6ab7007 to your computer and use it in GitHub Desktop.
as
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<concepts> | |
| #include<utility> | |
| struct as{template<class T>operator T(){std::unreachable();};template<class T>struct t{T&&x;template<class U>[[nodiscard]]constexpr decltype(static_cast<U>((T&&)x))operator->*(U(as::*)())noexcept(noexcept(static_cast<U>((T&&)x))){return static_cast<U>((T&&)x);}};};constexpr auto operator->*(auto&&x,std::same_as<as>auto)noexcept{return as::t((decltype(x))x);} | |
| #define as ->*::as()->*&::as::operator |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unlike
static_cast, this does not extend the lifetime of a temporary object bound to a reference:{ const int& x = static_cast<const int&>(0); } // The object is destroyed when the reference goes out of scope { const int& x = 0 as const int&; // The object is destroyed at the end of the full-expression }