Created
January 24, 2022 23:48
-
-
Save hjroh0315/a568cec85b055cd85a07d87c8ea936bd to your computer and use it in GitHub Desktop.
Chained Comparison인데, C++입니다
This file contains hidden or 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> | |
| using namespace std; | |
| template <class T> | |
| struct cmp | |
| { | |
| T val; bool truthy; | |
| cmp(T x): val(x), truthy(true){} | |
| cmp(T x, bool b): val(x), truthy(b){} | |
| cmp<T> operator<=(T v) | |
| { | |
| return cmp<T>{v,truthy&&(val<=v)}; | |
| } | |
| cmp<T> operator<(T v) | |
| { | |
| return cmp<T>{v,truthy&&(val<v)}; | |
| } | |
| cmp<T> operator>(T v) | |
| { | |
| return cmp<T>{v,truthy&&(val>v)}; | |
| } | |
| cmp<T> operator>=(T v) | |
| { | |
| return cmp<T>{v,truthy&&(val>=v)}; | |
| } | |
| operator bool() | |
| { | |
| return truthy; | |
| } | |
| }; | |
| int main() | |
| { | |
| if((cmp<int>)1<3<5<7<9)cout << "Hello, World!"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment