@@ -34,17 +34,30 @@
34#include <stdexcept>
34#include <stdexcept>
35#include <iso646.h> // mostly for MS Visual Studio compiler
35#include <iso646.h> // mostly for MS Visual Studio compiler
37−#define DECLARE_OPERATOR(op, ty, rty) \
37+#define DEFINE_OPERATOR(op, ty, rty) \
38− friend auto operator op (const any&, ty) -> rty; \
38+ inline friend auto operator op (const any& lhs, ty rhs) -> rty { \
39+ return lhs.cast<ty>() op rhs; \
39− friend auto operator op (ty, const any&) -> rty;
41+ inline friend auto operator op (ty lhs, const any& rhs) -> rty { \
42+ return lhs op rhs.cast<ty>(); \
45+#define DEFINE_INT_OPERATOR(op, rty) \
46+ inline friend auto operator op (const any& lhs, int rhs) -> rty { \
47+ return lhs.cast<long>() op (long)rhs; \
49+ inline friend auto operator op (int lhs, const any& rhs) -> rty { \
50+ return (long)lhs op rhs.cast<long>(); \
41#define DECLARE_COMPARISON_OPERATOR(op) \
53#define DECLARE_COMPARISON_OPERATOR(op) \
42 friend auto operator op (const any&, const any&) -> bool; \
54 friend auto operator op (const any&, const any&) -> bool; \
43− DECLARE_OPERATOR(op, long, bool) \
55+ DEFINE_OPERATOR(op, long, bool) \
44− DECLARE_OPERATOR(op, double, bool) \
56+ DEFINE_OPERATOR(op, double, bool) \
45− DECLARE_OPERATOR(op, char, bool) \
57+ DEFINE_OPERATOR(op, char, bool) \
46− DECLARE_OPERATOR(op, const char *, bool)
58+ DEFINE_INT_OPERATOR(op, bool) \
47−
59+ friend auto operator op (const any&, const char * const) -> bool; \
60+ friend auto operator op (const char * const, const any&) -> bool;
49namespace PureScript {
62namespace PureScript {
@@ -326,54 +339,49 @@ class any {
326 DECLARE_COMPARISON_OPERATOR(>)
339 DECLARE_COMPARISON_OPERATOR(>)
327 DECLARE_COMPARISON_OPERATOR(>=)
340 DECLARE_COMPARISON_OPERATOR(>=)
329− // For MS Visual Studio compiler: broken typed-enum workaround
330− DECLARE_OPERATOR(==, int, bool)
331− DECLARE_OPERATOR(!=, int, bool)
333 friend auto operator+(const any&, const any&) -> any;
342 friend auto operator+(const any&, const any&) -> any;
335− DECLARE_OPERATOR(+, long, long)
344+ DEFINE_OPERATOR(+, long, long)
336− DECLARE_OPERATOR(+, double, double)
345+ DEFINE_OPERATOR(+, double, double)
337− DECLARE_OPERATOR(+, char, char)
346+ DEFINE_OPERATOR(+, char, char)
347+ DEFINE_INT_OPERATOR(+, long)
338− DECLARE_OPERATOR(+, const char *, std::string)
348+ friend auto operator+(const any& lhs, const char * const rhs) -> std::string;
349+ friend auto operator+(const char * const lhs, const any& rhs) -> std::string;
340 friend auto operator-(const any&, const any&) -> any;
351 friend auto operator-(const any&, const any&) -> any;
342− DECLARE_OPERATOR(-, long, long)
353+ DEFINE_OPERATOR(-, long, long)
343− DECLARE_OPERATOR(-, double, double)
354+ DEFINE_OPERATOR(-, double, double)
344− DECLARE_OPERATOR(-, char, char)
355+ DEFINE_OPERATOR(-, char, char)
356+ DEFINE_INT_OPERATOR(-, long)
346 friend auto operator*(const any&, const any&) -> any;
358 friend auto operator*(const any&, const any&) -> any;
348− DECLARE_OPERATOR(*, long, long)
360+ DEFINE_OPERATOR(*, long, long)
349− DECLARE_OPERATOR(*, double, double)
361+ DEFINE_OPERATOR(*, double, double)
350− DECLARE_OPERATOR(*, char, char)
362+ DEFINE_OPERATOR(*, char, char)
363+ DEFINE_INT_OPERATOR(*, long)
352 friend auto operator/(const any&, const any&) -> any;
365 friend auto operator/(const any&, const any&) -> any;
354− DECLARE_OPERATOR(/, long, long)
367+ DEFINE_OPERATOR(/, long, long)
355− DECLARE_OPERATOR(/, double, double)
368+ DEFINE_OPERATOR(/, double, double)
356− DECLARE_OPERATOR(/, char, char)
369+ DEFINE_OPERATOR(/, char, char)
370+ DEFINE_INT_OPERATOR(/, long)
358 friend auto operator%(const any&, const any&) -> any;
372 friend auto operator%(const any&, const any&) -> any;
360− DECLARE_OPERATOR(%, long, long)
374+ DEFINE_OPERATOR(%, long, long)
361− DECLARE_OPERATOR(%, char, char)
375+ DEFINE_OPERATOR(%, char, char)
376+ DEFINE_INT_OPERATOR(%, long)
363 friend auto operator-(const any&) -> any; // unary negate
378 friend auto operator-(const any&) -> any; // unary negate
366−// For MS Visual Studio compiler: broken typed-enum workaround
367−inline auto operator==(const any& lhs, int rhs) -> bool {
368− return lhs == (long)rhs;
370−inline auto operator!=(const any& lhs, int rhs) -> bool {
371− return lhs != (long)rhs;
374} // namespace PureScript
381} // namespace PureScript
376−#undef DECLARE_OPERATOR
383+#undef DEFINE_OPERATOR
384+#undef DEFINE_INT_OPERATOR
377#undef DECLARE_COMPARISON_OPERATOR
385#undef DECLARE_COMPARISON_OPERATOR
379#endif // PureScript_HH
387#endif // PureScript_HH