From 1fde71f3f456692dfea1e48cfb8d65bd68f5e94b Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Tue, 13 Oct 2009 00:18:59 +0000 Subject: [PATCH] Add type generic comparison operations "eq", "gt", and "lt" and port the "contains" operation to use it --- include/chaiscript/language/chaiscript_prelude.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/chaiscript/language/chaiscript_prelude.hpp b/include/chaiscript/language/chaiscript_prelude.hpp index ba074d8..b32711c 100644 --- a/include/chaiscript/language/chaiscript_prelude.hpp +++ b/include/chaiscript/language/chaiscript_prelude.hpp @@ -12,6 +12,9 @@ #define CODE_STRING(x, y) #x ", " #y #define chaiscript_prelude CODE_STRING(\ +def lt(l, r) { if (call_exists(`<`, l, r)) { l < r } else { type_name(l) < type_name(r) } } \n\ +def gt(l, r) { if (call_exists(`>`, l, r)) { l > r } else { type_name(l) > type_name(r) } } \n\ +def eq(l, r) { if (call_exists(`==`, l, r)) { l == r } else { false } } \n\ def new(x) { eval(type_name(x))(); } \n\ def clone(x) : function_exists(type_name(x)) && call_exists(eval(type_name(x)), x) { eval(type_name(x))(x); } \n\ # to_string for Pair()\n\ @@ -92,7 +95,7 @@ def back_inserter(container) { \n\ def contains(container, item) : call_exists(range, container) { \n\ var t_range = range(container); \n\ while (!t_range.empty()) { \n\ - if (t_range.front() == item) { return true; } \n\ + if ( eq(t_range.front(), item) ) { return true; } \n\ t_range.pop_front(); \n\ } \n\ return false; \n\