Created
February 17, 2022 10:01
-
-
Save AlexisTM/21e6ebf4a8b9e952c18373386f43d0d7 to your computer and use it in GitHub Desktop.
++ Operator one liner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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