Skip to content

Instantly share code, notes, and snippets.

@hjroh0315
Created January 24, 2022 23:48
Show Gist options
  • Select an option

  • Save hjroh0315/a568cec85b055cd85a07d87c8ea936bd to your computer and use it in GitHub Desktop.

Select an option

Save hjroh0315/a568cec85b055cd85a07d87c8ea936bd to your computer and use it in GitHub Desktop.
Chained Comparison인데, C++입니다
#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