Add resize to stl list and vector; add reserve to stl vector
This commit is contained in:
parent
e57f11fcf4
commit
49ef5306a9
@ -292,6 +292,27 @@ namespace chaiscript
|
||||
}
|
||||
|
||||
|
||||
/// Add container resize concept to the given ContainerType
|
||||
/// http://www.cplusplus.com/reference/stl/
|
||||
template<typename ContainerType>
|
||||
ModulePtr resizable_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>())
|
||||
{
|
||||
m->add(fun([](ContainerType *a, ContainerType::size_type n, ContainerType::value_type val) { return a->resize(n, val); } ), "resize");
|
||||
m->add(fun([](ContainerType *a, ContainerType::size_type n) { return a->resize(n, ContainerType::value_type()); } ), "resize");
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
/// Add container reserve concept to the given ContainerType
|
||||
/// http://www.cplusplus.com/reference/stl/
|
||||
template<typename ContainerType>
|
||||
ModulePtr reservable_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>())
|
||||
{
|
||||
m->add(fun([](ContainerType *a, ContainerType::size_type n) { return a->reserve(n); } ), "reserve");
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
/// Add container concept to the given ContainerType
|
||||
/// http://www.sgi.com/tech/stl/Container.html
|
||||
template<typename ContainerType>
|
||||
@ -581,6 +602,7 @@ namespace chaiscript
|
||||
front_insertion_sequence_type<ListType>(type, m);
|
||||
back_insertion_sequence_type<ListType>(type, m);
|
||||
sequence_type<ListType>(type, m);
|
||||
resizable_type<ListType>(type, m);
|
||||
container_type<ListType>(type, m);
|
||||
default_constructible_type<ListType>(type, m);
|
||||
assignable_type<ListType>(type, m);
|
||||
@ -612,6 +634,8 @@ namespace chaiscript
|
||||
back_insertion_sequence_type<VectorType>(type, m);
|
||||
sequence_type<VectorType>(type, m);
|
||||
random_access_container_type<VectorType>(type, m);
|
||||
resizable_type<VectorType>(type, m);
|
||||
reservable_type<VectorType>(type, m);
|
||||
container_type<VectorType>(type, m);
|
||||
default_constructible_type<VectorType>(type, m);
|
||||
assignable_type<VectorType>(type, m);
|
||||
|
13
unittests/list_resize.chai
Normal file
13
unittests/list_resize.chai
Normal file
@ -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[5], "AAA");
|
||||
|
||||
list.resize(0);
|
||||
assert_equal(list.size(), 0);
|
||||
|
7
unittests/vector_reserve.chai
Normal file
7
unittests/vector_reserve.chai
Normal file
@ -0,0 +1,7 @@
|
||||
load_module("stl_extra");
|
||||
|
||||
auto uint16v = u16vector();
|
||||
|
||||
uint16v.reserve(5);
|
||||
assert_true(uint16v.size() >= 5);
|
||||
|
13
unittests/vector_resize.chai
Normal file
13
unittests/vector_resize.chai
Normal file
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user