Skip to content

Instantly share code, notes, and snippets.

@flomnes
Created March 10, 2025 09:50
Show Gist options
  • Save flomnes/5b62b714e5f90ce625954a32f5e3d310 to your computer and use it in GitHub Desktop.
Save flomnes/5b62b714e5f90ce625954a32f5e3d310 to your computer and use it in GitHub Desktop.
Order execution
#include <iostream>
#include <string>
#include <string_view>
#include <utility>
template<class T>
T&& log(T&& in, std::string_view msg)
{
std::cout << msg << std::endl;
return std::move(in);
}
int f(std::string&& a, std::string&& b)
{
auto q = std::move(a);
auto r = std::move(b);
return q.size() + r.size();
}
int main()
{
std::string m("VP");
std::cout << f(log(std::move(m), "first"), log(std::move(m), "second")) << std::endl;
/* Possible output
second
first
2
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment