Add py::dict() keyword constructor

This commit is contained in:
Dean Moldovan
2016-08-30 12:05:53 +02:00
parent 66aa2728f4
commit 15a112f8ff
5 changed files with 26 additions and 16 deletions

View File

@@ -1148,6 +1148,10 @@ inline object handle::operator()(detail::args_proxy args, detail::kwargs_proxy k
return result;
}
template <typename... Args, typename /*SFINAE*/>
dict::dict(Args &&...args)
: dict(detail::unpacking_collector<>(std::forward<Args>(args)...).kwargs()) { }
#define PYBIND11_MAKE_OPAQUE(Type) \
namespace pybind11 { namespace detail { \
template<> class type_caster<Type> : public type_caster_base<Type> { }; \

View File

@@ -589,6 +589,9 @@ public:
dict() : object(PyDict_New(), false) {
if (!m_ptr) pybind11_fail("Could not allocate dict object!");
}
template <typename... Args,
typename = detail::enable_if_t<detail::all_of_t<detail::is_keyword_or_ds, Args...>::value>>
dict(Args &&...args);
size_t size() const { return (size_t) PyDict_Size(m_ptr); }
detail::dict_iterator begin() const { return (++detail::dict_iterator(*this, 0)); }
detail::dict_iterator end() const { return detail::dict_iterator(); }