Skip to content

Instantly share code, notes, and snippets.

@AlexisTM
Created February 17, 2022 10:01
Show Gist options
  • Save AlexisTM/21e6ebf4a8b9e952c18373386f43d0d7 to your computer and use it in GitHub Desktop.
Save AlexisTM/21e6ebf4a8b9e952c18373386f43d0d7 to your computer and use it in GitHub Desktop.
++ Operator one liner
#include <iostream>
struct S {
int value = 0;
decltype(auto) operator++(auto... t) {
return ((*this = {value + 1}), ..., S{value - 1 + t});
}
};
int main() {
S s;
std::cout << (s++).value;
std::cout << s.value;
std::cout << (++s).value;
std::cout << s.value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment