Make inplace vector construction result in const temp return. Also clean up construction of vectors in code

This commit is contained in:
Jason Turner
2010-10-02 22:19:51 +00:00
parent 512d6b342d
commit fa2a7045a7
2 changed files with 13 additions and 19 deletions

View File

@@ -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;
}