Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <functional>
- //#include <cstdint> codepad doesn't recognize it
- #include <stdint.h>
- #if __cplusplus >= 201103L
- # define CONSTEXPR constexpr
- #else
- # define CONSTEXPR
- #endif
- namespace System
- {
- template <typename Type, template <typename> class Oper>
- struct CmpResult {
- CONSTEXPR CmpResult(Type v, bool r): value(v), last_cmp_res(r) {}
- #if __cplusplus >= 201103L
- constexpr explicit operator bool() const {
- return this->last_cmp_res;
- }
- #else
- operator void *() const {
- return reinterpret_cast<void *>(this->last_cmp_res);
- }
- #endif
- Type value;
- bool last_cmp_res;
- private:
- #if __cplusplus >= 201103L
- CmpResult& operator =(const CmpResult&) = delete;
- #else
- CmpResult& operator =(const CmpResult&);
- #endif
- };
- template <typename Type>
- struct ValueType
- {
- CONSTEXPR ValueType(Type val): value(val) {}
- #define DECL_OPER(op, op_type)\
- CONSTEXPR friend CmpResult<ValueType, op_type> operator op(ValueType left, ValueType right) {\
- return CmpResult<ValueType, op_type>(right, left.value op right.value);\
- }\
- CONSTEXPR friend CmpResult<ValueType, op_type> operator op(CmpResult<ValueType, op_type> left, ValueType right) {\
- return left ? CmpResult<ValueType, op_type>(right, bool(left.value op right.value)) : CmpResult<ValueType, op_type>(0, false);\
- }
- DECL_OPER(<, std::less)
- DECL_OPER(<=, std::less)
- DECL_OPER(>, std::greater)
- DECL_OPER(>=, std::greater)
- #undef DECL_OPER
- Type value;
- };
- typedef ValueType<int8_t> SByte;
- typedef ValueType<uint8_t> Byte;
- typedef ValueType<int16_t> Int16;
- typedef ValueType<uint16_t> UInt16;
- typedef ValueType<int32_t> Int32;
- typedef ValueType<uint32_t> UInt32;
- typedef ValueType<int64_t> Int64;
- typedef ValueType<uint64_t> UInt64;
- typedef ValueType<float> Single;
- typedef ValueType<double> Double;
- }
- int main()
- {
- using namespace std;
- using namespace System;
- Single d = 5;
- if (3 < d <= 6.5f)
- std::puts("true");
- else
- std::puts("false");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement