Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
Adaptive return type
#include <iostream> using InnerType = int; struct Any { Any(InnerType val) : m_val{ val } { std::cout << "my ptrs = [" << this << " : " << &m_val << "]\n"; } struct Adaptor { operator InnerType*() const noexcept { return std::addressof(any.m_val); }; operator Any*() const noexcept { return std::addressof(any); }; operator void*() const noexcept { return std::addressof(any); }; Any &any; }; const Adaptor operator&() { return { *this }; } private: bool _filler{}; InnerType m_val{}; }; int main() { Any any{ 123 }; Any *anyPtr = &any; std::cout << "Any ptr = " << anyPtr << "\n"; InnerType *itypePtr = &any; std::cout << "Inner type ptr = " << itypePtr << " : val = " << *itypePtr << "\n"; }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
hangman
MSVC14 <experimental/generator> header
Competitive - Algorithm for max number of superior characters
#22.1
template test
algorithm_1
move swap
VS struct_member_name
ExtThes_Uniquify
Compile time creation of class member stl container (const std::array) filled with elements.
Please log in to post a comment.