Make inplace vector construction result in const temp return. Also clean up construction of vectors in code
This commit is contained in:
@@ -181,11 +181,14 @@ namespace detail {
|
||||
ModulePtr random_access_container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module()))
|
||||
{
|
||||
typedef typename ContainerType::reference(ContainerType::*indexoper)(size_t);
|
||||
typedef typename ContainerType::const_reference(ContainerType::*constindexoper)(size_t) const;
|
||||
|
||||
//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(boost::function<typename ContainerType::reference (ContainerType *, int)>(boost::mem_fn(static_cast<indexoper>(&ContainerType::at)))), "[]");
|
||||
m->add(
|
||||
fun(boost::function<typename ContainerType::const_reference (const ContainerType *, int)>(boost::mem_fn(static_cast<constindexoper>(&ContainerType::at)))), "[]");
|
||||
|
||||
return m;
|
||||
}
|
||||
|
@@ -372,15 +372,11 @@ namespace chaiscript
|
||||
* Evaluates (and generates) an inline array initialization
|
||||
*/
|
||||
Boxed_Value Inline_Array_AST_Node::eval(Dispatch_Engine &ss) {
|
||||
try {
|
||||
Boxed_Value retval = ss.call_function("Vector");
|
||||
std::vector<Boxed_Value> vec;
|
||||
if (this->children.size() > 0) {
|
||||
for (size_t i = 0; i < this->children[0]->children.size(); ++i) {
|
||||
try {
|
||||
ss.call_function("push_back", retval, this->children[0]->children[i]->eval(ss));
|
||||
}
|
||||
catch (const dispatch_error &) {
|
||||
throw Eval_Error("Can not find appropriate 'push_back'");
|
||||
vec.push_back(this->children[0]->children[i]->eval(ss));
|
||||
}
|
||||
catch(Eval_Error &ee) {
|
||||
ee.call_stack.push_back(this->children[0]->children[i]);
|
||||
@@ -389,12 +385,7 @@ namespace chaiscript
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
catch (const dispatch_error &) {
|
||||
throw Eval_Error("Can not find appropriate 'Vector()'");
|
||||
}
|
||||
|
||||
return const_var(vec);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user