diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index f4067806..f557aab0 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -348,17 +348,13 @@ namespace chaiscript static std::vector do_return_boxed_value_vector(FunctionType f, const dispatch::Proxy_Function_Base *b) { - typedef decltype(std::mem_fn(f)) MemFunType; - typedef typename MemFunType::result_type Vector; - - Vector v = (b->*f)(); + auto v = (b->*f)(); std::vector vbv; - for (typename Vector::const_iterator itr = v.begin(); - itr != v.end(); - ++itr) + + for (const auto &o: v) { - vbv.push_back(const_var(*itr)); + vbv.push_back(const_var(o)); } return vbv; diff --git a/include/chaiscript/dispatchkit/dynamic_object.hpp b/include/chaiscript/dispatchkit/dynamic_object.hpp index e94e893f..1126f28e 100644 --- a/include/chaiscript/dispatchkit/dynamic_object.hpp +++ b/include/chaiscript/dispatchkit/dynamic_object.hpp @@ -111,9 +111,7 @@ namespace chaiscript virtual std::vector get_contained_functions() const { - std::vector fs; - fs.push_back(m_func); - return fs; + return {m_func}; } diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index c14e1e79..e3ab3dc1 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -51,7 +51,7 @@ namespace chaiscript /// if the function is variadic or takes no arguments (arity of 0 or -1), the returned /// value containes exactly 1 Type_Info object: the return type /// \returns the types of all parameters. - std::vector get_param_types() const { return m_types; } + const std::vector &get_param_types() const { return m_types; } virtual bool operator==(const Proxy_Function_Base &) const = 0; virtual bool call_match(const std::vector &vals) const = 0; @@ -262,7 +262,7 @@ namespace chaiscript // For the return type types.push_back(chaiscript::detail::Get_Type_Info::get()); - if (arity >= 0) + if (arity > 0) { for (int i = 0; i < arity; ++i) { @@ -378,6 +378,7 @@ namespace chaiscript const std::vector &t_args) { assert(t_f->get_arity() < 0 || t_f->get_arity() == static_cast(t_args.size())); + if (t_f->get_arity() < 0) { return std::vector(); } std::vector types = t_f->get_param_types(); @@ -419,8 +420,8 @@ namespace chaiscript Proxy_Function_Impl(const std::function &f) : Proxy_Function_Base(detail::build_param_type_list(static_cast(0))), m_f(f), m_dummy_func(0) - { - } + { + } virtual ~Proxy_Function_Impl() {} @@ -430,13 +431,11 @@ namespace chaiscript return pimpl != 0; } - virtual int get_arity() const { return static_cast(m_types.size()) - 1; } - virtual bool call_match(const std::vector &vals) const { if (int(vals.size()) != get_arity()) @@ -478,8 +477,8 @@ namespace chaiscript Attribute_Access(T Class::* t_attr) : Proxy_Function_Base(param_types()), m_attr(t_attr) - { - } + { + } virtual ~Attribute_Access() {} @@ -487,6 +486,7 @@ namespace chaiscript { const Attribute_Access * aa = dynamic_cast *>(&t_func); + if (aa) { return m_attr == aa->m_attr; } else { @@ -537,11 +537,9 @@ namespace chaiscript private: static std::vector param_types() { - std::vector v; - v.push_back(user_type()); - v.push_back(user_type()); - return v; + return {user_type(), user_type()}; } + T Class::* m_attr; }; } @@ -576,7 +574,7 @@ namespace chaiscript * function is found or throw dispatch_error if no matching function is found */ template - Boxed_Value dispatch(InItr begin, InItr end, + Boxed_Value dispatch(InItr begin, const InItr &end, const std::vector &plist) { while (begin != end)