Various cleanups and fixes for older compilers

This commit is contained in:
Jason Turner
2015-05-22 19:40:56 -06:00
parent df724b5c33
commit e0234d942e
5 changed files with 41 additions and 42 deletions

View File

@@ -243,18 +243,18 @@ namespace chaiscript
template<typename ContainerType>
ModulePtr random_access_container_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>())
{
// cppcheck-suppress syntaxError
typedef typename ContainerType::reference(ContainerType::*indexoper)(size_t);
//In the interest of runtime safety for the m, we prefer the at() method for [] access,
//to throw an exception in an out of bounds condition.
m->add(
fun(std::function<typename ContainerType::reference (ContainerType *, int)>
(std::mem_fn(static_cast<indexoper>(&ContainerType::at)))), "[]");
fun(
[](ContainerType &c, int index) -> typename ContainerType::reference {
return c.at(index);
}), "[]");
m->add(
fun(
[](const ContainerType *c, int index) -> typename ContainerType::const_reference {
return c->at(index);
[](const ContainerType &c, int index) -> typename ContainerType::const_reference {
return c.at(index);
}), "[]");
return m;