template <typename T, typename U> void printSizes() { int status = 0; char *realnameT = abi::__cxa_demangle(typeid(T).name(), 0, 0, &status); char *realnameU = abi::__cxa_demangle(typeid(U).name(), 0, 0, &status); std::cout << "Type: " << (realnameT ? realnameT : typeid(T).name()) << '\n'; std::cout << "Size: " << sizeof(T) << '\n'; std::cout << "Type: " << (realnameU ? realnameU : typeid(U).name()) << '\n'; std::cout << "Size: " << sizeof(U) << '\n'; std::cout << "Sizeof std::expected: "; st...| godbolt.org
In this article, we’ll go through a new vocabulary type introduced in C++23. std::expected is a type specifically designed to return results from a function, along with the extra error information. Motivation Imagine you’re expecting a certain result from a function, but oops… things don’t always go as planned:| C++ Stories