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 <ranges> #include <vector> #include <algorithm> #if 1 template<class RangeIn, class RangeOut> void moveOrCopy(RangeIn& from, RangeOut& to) { std::ranges::copy(from, std::back_inserter(to)); } #endif template<class RangeIn, class RangeOut> requires std::is_rvalue_reference_v<RangeIn&&> void moveOrCopy(RangeIn&& from, RangeOut& to) { std::ranges::move(from, std::back_inserter(to)); } void test() { std::vector<int> a, b; moveOrCopy(a, b); // copy moveOrCopy(std::move(a), b); // move }
Insight:
Console: