Request Short Link
C++ 98
C++ 11
C++ 14
C++ 17
C++ 20
C++ 23
C++ 2c
for-loops as while-loops
array subscription
Show all implicit casts
Show all template parameters of a CallExpr
Use libc++
Transform std::initializer_list
Show noexcept internals
Show padding information
Show coroutine transformation
Show C++ to C transformation
Show object lifetime
Default
15
18
20
22
26
More
GitHub
Patreon
Issues
About
Policies
Examples
C++ Insights @ YouTube
Settings
Version
New C++ Insights Episode
×
Made by
Andreas Fertig
Powered by
Flask
and
CodeMirror
Source:
#include <string> #include <type_traits> class person { public: person(std::string name, std::string surname) : m_name{std::move(name)} , m_surname{std::move(surname)} {} private: std::string m_name, m_surname; }; class string_builder { public: string_builder(std::string& destination) : m_destination{std::move(destination)} {} private: std::string m_destination; }; template <typename T> decltype(auto) forward_arg(std::remove_reference_t<T>& val) { if constexpr(std::is_lvalue_reference_v<T>) return val; else return std::move(val); } template <typename T, typename... Args> T construct_v4(Args&&... args) { return T{forward_arg<Args>(args)...}; } int main() { auto name4 = std::string{"Jan"}; const auto surname = std::string{"Kowalski"}; auto p4 = construct_v4<person>(std::move(name4), surname); auto string = std::string{}; auto sb = construct_v4<string_builder>(string); }
Insight:
Console: