From dfd89a608123645badd3e77cdcdfaa683f405857 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Thu, 16 Mar 2017 11:44:01 +0100 Subject: [PATCH] remove all pybind11 namespace prefixes from stl_bind.h --- include/pybind11/stl_bind.h | 78 ++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/include/pybind11/stl_bind.h b/include/pybind11/stl_bind.h index 300e8af9a..897188220 100644 --- a/include/pybind11/stl_bind.h +++ b/include/pybind11/stl_bind.h @@ -70,7 +70,7 @@ void vector_if_copy_constructible(enable_if_t< std::is_copy_constructible::value && std::is_copy_constructible::value, Class_> &cl) { - cl.def(pybind11::init(), "Copy constructor"); + cl.def(init(), "Copy constructor"); } template @@ -93,7 +93,7 @@ void vector_if_equal_operator(enable_if_t::value, Class_> if (p != v.end()) v.erase(p); else - throw pybind11::value_error(); + throw value_error(); }, arg("x"), "Remove the first item from the list whose value is x. " @@ -155,7 +155,7 @@ void vector_modifiers(enable_if_t= v.size()) - throw pybind11::index_error(); + throw index_error(); T t = v[i]; v.erase(v.begin() + (DiffType) i); return t; @@ -178,7 +178,7 @@ void vector_modifiers(enable_if_t= v.size()) - throw pybind11::index_error(); + throw index_error(); v[i] = t; } ); @@ -189,7 +189,7 @@ void vector_modifiers(enable_if_treserve((size_t) slicelength); @@ -208,7 +208,7 @@ void vector_modifiers(enable_if_t= v.size()) - throw pybind11::index_error(); + throw index_error(); v.erase(v.begin() + DiffType(i)); }, "Delete the list elements at index ``i``" @@ -235,7 +235,7 @@ void vector_modifiers(enable_if_t::value, Class_> &cl) cl.def("__getitem__", [](Vector &v, SizeType i) -> T & { if (i >= v.size()) - throw pybind11::index_error(); + throw index_error(); return v[i]; }, return_value_policy::reference_internal // ref + keepalive @@ -274,7 +274,7 @@ void vector_accessor(enable_if_t::value, Class_> &cl) cl.def("__iter__", [](Vector &v) { - return pybind11::make_iterator< + return make_iterator< return_value_policy::reference_internal, ItType, ItType, T&>( v.begin(), v.end()); }, @@ -291,14 +291,14 @@ void vector_accessor(enable_if_t::value, Class_> &cl) cl.def("__getitem__", [](const Vector &v, SizeType i) -> T { if (i >= v.size()) - throw pybind11::index_error(); + throw index_error(); return v[i]; } ); cl.def("__iter__", [](Vector &v) { - return pybind11::make_iterator< + return make_iterator< return_value_policy::copy, ItType, ItType, T>( v.begin(), v.end()); }, @@ -331,29 +331,29 @@ template auto vector_if_insertion_operator(Cl template struct vector_has_data_and_format : std::false_type {}; template -struct vector_has_data_and_format::format(), std::declval().data()), typename Vector::value_type*>::value>> : std::true_type {}; +struct vector_has_data_and_format::format(), std::declval().data()), typename Vector::value_type*>::value>> : std::true_type {}; // Add the buffer interface to a vector template -enable_if_t...>::value> +enable_if_t...>::value> vector_buffer(Class_& cl) { using T = typename Vector::value_type; static_assert(vector_has_data_and_format::value, "There is not an appropriate format descriptor for this vector"); // numpy.h declares this for arbitrary types, but it may raise an exception and crash hard at runtime if PYBIND11_NUMPY_DTYPE hasn't been called, so check here - py::format_descriptor::format(); + format_descriptor::format(); - cl.def_buffer([](Vector& v) -> py::buffer_info { - return py::buffer_info(v.data(), sizeof(T), py::format_descriptor::format(), 1, {v.size()}, {sizeof(T)}); + cl.def_buffer([](Vector& v) -> buffer_info { + return buffer_info(v.data(), sizeof(T), format_descriptor::format(), 1, {v.size()}, {sizeof(T)}); }); - cl.def("__init__", [](Vector& vec, py::buffer buf) { + cl.def("__init__", [](Vector& vec, buffer buf) { auto info = buf.request(); if (info.ndim != 1 || info.strides[0] <= 0 || info.strides[0] % sizeof(T)) - throw pybind11::type_error("Only valid 1D buffers can be copied to a vector"); + throw type_error("Only valid 1D buffers can be copied to a vector"); if (!detail::compare_buffer_info::compare(info) || sizeof(T) != info.itemsize) - throw pybind11::type_error("Format mismatch (Python: " + info.format + " C++: " + py::format_descriptor::format() + ")"); + throw type_error("Format mismatch (Python: " + info.format + " C++: " + format_descriptor::format() + ")"); new (&vec) Vector(); vec.reserve(info.shape[0]); T *p = static_cast(info.ptr); @@ -367,7 +367,7 @@ vector_buffer(Class_& cl) { } template -enable_if_t...>::value> vector_buffer(Class_&) {} +enable_if_t...>::value> vector_buffer(Class_&) {} NAMESPACE_END(detail) @@ -375,15 +375,15 @@ NAMESPACE_END(detail) // std::vector // template , typename... Args> -pybind11::class_ bind_vector(pybind11::module &m, std::string const &name, Args&&... args) { - using Class_ = pybind11::class_; +class_ bind_vector(module &m, std::string const &name, Args&&... args) { + using Class_ = class_; Class_ cl(m, name.c_str(), std::forward(args)...); - // Declare the buffer interface if a py::buffer_protocol() is passed in + // Declare the buffer interface if a buffer_protocol() is passed in detail::vector_buffer(cl); - cl.def(pybind11::init<>()); + cl.def(init<>()); // Register copy constructor (if possible) detail::vector_if_copy_constructible(cl); @@ -414,7 +414,7 @@ pybind11::class_ bind_vector(pybind11::module &m, std::stri #if 0 // C++ style functions deprecated, leaving it here as an example - cl.def(pybind11::init()); + cl.def(init()); cl.def("resize", (void (Vector::*) (size_type count)) & Vector::resize, @@ -423,7 +423,7 @@ pybind11::class_ bind_vector(pybind11::module &m, std::stri cl.def("erase", [](Vector &v, SizeType i) { if (i >= v.size()) - throw pybind11::index_error(); + throw index_error(); v.erase(v.begin() + i); }, "erases element at index ``i``"); @@ -442,12 +442,12 @@ pybind11::class_ bind_vector(pybind11::module &m, std::stri cl.def("front", [](Vector &v) { if (v.size()) return v.front(); - else throw pybind11::index_error(); + else throw index_error(); }, "access the first element"); cl.def("back", [](Vector &v) { if (v.size()) return v.back(); - else throw pybind11::index_error(); + else throw index_error(); }, "access the last element "); #endif @@ -530,14 +530,14 @@ template auto map_if_insertion_operator(Class_ & NAMESPACE_END(detail) template , typename... Args> -pybind11::class_ bind_map(module &m, const std::string &name, Args&&... args) { +class_ bind_map(module &m, const std::string &name, Args&&... args) { using KeyType = typename Map::key_type; using MappedType = typename Map::mapped_type; - using Class_ = pybind11::class_; + using Class_ = class_; Class_ cl(m, name.c_str(), std::forward(args)...); - cl.def(pybind11::init<>()); + cl.def(init<>()); // Register stream insertion operator (if possible) detail::map_if_insertion_operator(cl, name); @@ -548,20 +548,20 @@ pybind11::class_ bind_map(module &m, const std::string &name, ); cl.def("__iter__", - [](Map &m) { return pybind11::make_key_iterator(m.begin(), m.end()); }, - pybind11::keep_alive<0, 1>() /* Essential: keep list alive while iterator exists */ + [](Map &m) { return make_key_iterator(m.begin(), m.end()); }, + keep_alive<0, 1>() /* Essential: keep list alive while iterator exists */ ); cl.def("items", - [](Map &m) { return pybind11::make_iterator(m.begin(), m.end()); }, - pybind11::keep_alive<0, 1>() /* Essential: keep list alive while iterator exists */ + [](Map &m) { return make_iterator(m.begin(), m.end()); }, + keep_alive<0, 1>() /* Essential: keep list alive while iterator exists */ ); cl.def("__getitem__", [](Map &m, const KeyType &k) -> MappedType & { auto it = m.find(k); if (it == m.end()) - throw pybind11::key_error(); + throw key_error(); return it->second; }, return_value_policy::reference_internal // ref + keepalive @@ -574,7 +574,7 @@ pybind11::class_ bind_map(module &m, const std::string &name, [](Map &m, const KeyType &k) { auto it = m.find(k); if (it == m.end()) - throw pybind11::key_error(); + throw key_error(); return m.erase(it); } );