diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index 7ba588b..b9e0a9f 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -292,6 +292,40 @@ namespace chaiscript } + /// Add container resize concept to the given ContainerType + /// http://www.cplusplus.com/reference/stl/ + template + void resizable_type(const std::string &/*type*/, Module& m) + { + m.add(fun([](ContainerType *a, typename ContainerType::size_type n, const typename ContainerType::value_type& val) { return a->resize(n, val); } ), "resize"); + m.add(fun([](ContainerType *a, typename ContainerType::size_type n) { return a->resize(n); } ), "resize"); + } + template + ModulePtr resizable_type(const std::string &type) + { + auto m = std::make_shared(); + resizable_type(type, *m); + return m; + } + + + /// Add container reserve concept to the given ContainerType + /// http://www.cplusplus.com/reference/stl/ + template + void reservable_type(const std::string &/*type*/, Module& m) + { + m.add(fun([](ContainerType *a, typename ContainerType::size_type n) { return a->reserve(n); } ), "reserve"); + m.add(fun([](const ContainerType *a) { return a->capacity(); } ), "capacity"); + } + template + ModulePtr reservable_type(const std::string &type) + { + auto m = std::make_shared(); + reservable_type(type, *m); + return m; + } + + /// Add container concept to the given ContainerType /// http://www.sgi.com/tech/stl/Container.html template @@ -581,6 +615,7 @@ namespace chaiscript front_insertion_sequence_type(type, m); back_insertion_sequence_type(type, m); sequence_type(type, m); + resizable_type(type, m); container_type(type, m); default_constructible_type(type, m); assignable_type(type, m); @@ -612,6 +647,8 @@ namespace chaiscript back_insertion_sequence_type(type, m); sequence_type(type, m); random_access_container_type(type, m); + resizable_type(type, m); + reservable_type(type, m); container_type(type, m); default_constructible_type(type, m); assignable_type(type, m); diff --git a/include/chaiscript/dispatchkit/handle_return.hpp b/include/chaiscript/dispatchkit/handle_return.hpp index 8ac2d9e..2b770ac 100644 --- a/include/chaiscript/dispatchkit/handle_return.hpp +++ b/include/chaiscript/dispatchkit/handle_return.hpp @@ -100,6 +100,24 @@ namespace chaiscript } }; + template + struct Handle_Return + { + static Boxed_Value handle(Ret *p) + { + return Boxed_Value(p, true); + } + }; + + template + struct Handle_Return + { + static Boxed_Value handle(const Ret *p) + { + return Boxed_Value(p, true); + } + }; + template struct Handle_Return { diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index deae941..f8cb549 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -23,6 +23,7 @@ #include "chaiscript_optimizer.hpp" #if defined(CHAISCRIPT_MSVC) && defined(max) && defined(min) +#define CHAISCRIPT_PUSHED_MIN_MAX #pragma push_macro("max") // Why Microsoft? why? This is worse than bad #undef max #pragma push_macro("min") @@ -2331,7 +2332,8 @@ namespace chaiscript } -#ifdef CHAISCRIPT_MSVC +#if defined(CHAISCRIPT_MSVC) && defined(CHAISCRIPT_PUSHED_MIN_MAX) +#undef CHAISCRIPT_PUSHED_MIN_MAX #pragma pop_macro("min") #pragma pop_macro("max") #endif diff --git a/unittests/list_resize.chai b/unittests/list_resize.chai new file mode 100644 index 0000000..0d6f05c --- /dev/null +++ b/unittests/list_resize.chai @@ -0,0 +1,13 @@ +load_module("stl_extra"); + +auto list = List(); + +list.resize(2); +assert_equal(list.size(), 2); + +list.resize(6, "AAA"); +assert_equal(list.back(), "AAA"); + +list.resize(0); +assert_equal(list.size(), 0); + diff --git a/unittests/vector_reserve.chai b/unittests/vector_reserve.chai new file mode 100644 index 0000000..68c8dbd --- /dev/null +++ b/unittests/vector_reserve.chai @@ -0,0 +1,7 @@ +load_module("stl_extra"); + +auto uint16v = u16vector(); + +uint16v.reserve(5); +assert_true(uint16v.capacity() >= 5); + diff --git a/unittests/vector_resize.chai b/unittests/vector_resize.chai new file mode 100644 index 0000000..577ae6d --- /dev/null +++ b/unittests/vector_resize.chai @@ -0,0 +1,13 @@ +load_module("stl_extra"); + +auto uint16v = u16vector(); + +uint16v.resize(2); +assert_equal(uint16v.size(), 2); + +uint16v.resize(6, 3); +assert_equal(uint16v[5], 3); + +uint16v.resize(0); +assert_equal(uint16v.size(), 0); +