Lightning Talk: Source/Sink vs. Ranges in C++ - What's the Difference?
summary
Quick experiments in Compiler Explorer compare a standard std::copy implementation to versions that use explicit source/sink functions and small optional-wrapping lambdas. The compiler emits a single optimized memcpy for the simple loop, for the sink/source wrapper, and even when stacking three layers, showing the optimizer collapses the abstractions to one memcpy. Examples include the exact code patterns used, generated asm output, and the surprising “one memcpy” count across variants.
AI-written summary · about
chapters (3)
related talks
27mReturn Value Optimization: Harder Than It Looks
01h 25mComparing 'Classic C++' and 'Modern C++' Ways to Solve Programming Tasks
01h 01mFrom STL to Ranges: Using Ranges Effectively
57mAliasing: Risks, Opportunities and Techniques
55mBreaking Dependencies: Type Erasure - The Implementation Details
59mModern C++ for Fun and Profit: This isn’t your old C++
05mCopy Elision
50mC++ Costless Abstractions: the compiler view
