From ec8ebb766a39e0a3af0bd650a8e6dd332b56571a Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Tue, 12 Jan 2021 10:53:42 -0800 Subject: [PATCH] Pure `clang-format --style=file -i` change, with two `clang-format off` directives. --- tests/test_classh_wip.cpp | 105 ++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 50 deletions(-) diff --git a/tests/test_classh_wip.cpp b/tests/test_classh_wip.cpp index 1767af9d3..d7e99ceea 100644 --- a/tests/test_classh_wip.cpp +++ b/tests/test_classh_wip.cpp @@ -8,7 +8,11 @@ namespace pybind11_tests { namespace classh_wip { -struct mpty { std::string mtxt; }; +struct mpty { + std::string mtxt; +}; + +// clang-format off mpty rtrn_mpty_valu() { mpty obj; return obj; } mpty&& rtrn_mpty_rref() { mpty obj; return std::move(obj); } @@ -36,8 +40,10 @@ std::unique_ptr rtrn_mpty_uqcp() { return std::unique_ptr obj) { return "pass_uqmp:" + obj->mtxt; } std::string pass_mpty_uqcp(std::unique_ptr obj) { return "pass_uqcp:" + obj->mtxt; } -} // namespace classh_wip -} // namespace pybind11_tests +// clang-format on + +} // namespace classh_wip +} // namespace pybind11_tests namespace pybind11 { namespace detail { @@ -47,15 +53,16 @@ using namespace pybind11_tests::classh_wip; template struct smart_holder_type_caster_load { bool load(handle src, bool /*convert*/) { - if (!isinstance(src)) return false; - auto inst = reinterpret_cast(src.ptr()); - auto v_h = inst->get_value_and_holder(get_type_info(typeid(T))); + if (!isinstance(src)) + return false; + auto inst = reinterpret_cast(src.ptr()); + auto v_h = inst->get_value_and_holder(get_type_info(typeid(T))); smhldr_ptr = &v_h.holder(); return true; } - protected: - pybindit::memory::smart_holder* smhldr_ptr = nullptr; +protected: + pybindit::memory::smart_holder *smhldr_ptr = nullptr; }; template <> @@ -65,48 +72,41 @@ struct type_caster : smart_holder_type_caster_load { // static handle cast(mpty, ...) // is redundant (leads to ambiguous overloads). - static handle cast(mpty&& /*src*/, - return_value_policy /*policy*/, - handle /*parent*/) { + static handle cast(mpty && /*src*/, return_value_policy /*policy*/, handle /*parent*/) { return str("cast_rref").release(); } - static handle cast(mpty const& /*src*/, - return_value_policy /*policy*/, - handle /*parent*/) { + static handle cast(mpty const & /*src*/, return_value_policy /*policy*/, handle /*parent*/) { return str("cast_cref").release(); } - static handle cast(mpty& /*src*/, - return_value_policy /*policy*/, - handle /*parent*/) { + static handle cast(mpty & /*src*/, return_value_policy /*policy*/, handle /*parent*/) { return str("cast_mref").release(); } - static handle cast(mpty const* /*src*/, - return_value_policy /*policy*/, - handle /*parent*/) { + static handle cast(mpty const * /*src*/, return_value_policy /*policy*/, handle /*parent*/) { return str("cast_cptr").release(); } - static handle cast(mpty* /*src*/, - return_value_policy /*policy*/, - handle /*parent*/) { + static handle cast(mpty * /*src*/, return_value_policy /*policy*/, handle /*parent*/) { return str("cast_mptr").release(); } template using cast_op_type = conditional_t< - std::is_same, mpty const*>::value, mpty const*, + std::is_same, mpty const *>::value, + mpty const *, conditional_t< - std::is_same, mpty*>::value, mpty*, + std::is_same, mpty *>::value, + mpty *, conditional_t< - std::is_same::value, mpty const&, - conditional_t< - std::is_same::value, mpty&, - conditional_t< - std::is_same::value, mpty&&, - mpty>>>>>; + std::is_same::value, + mpty const &, + conditional_t::value, + mpty &, + conditional_t::value, mpty &&, mpty>>>>>; + + // clang-format off operator mpty() { return smhldr_ptr->lvalue_ref(); } operator mpty&&() && { return smhldr_ptr->rvalue_ref(); } @@ -114,19 +114,22 @@ struct type_caster : smart_holder_type_caster_load { operator mpty&() { return smhldr_ptr->lvalue_ref(); } operator mpty const*() { return smhldr_ptr->as_raw_ptr_unowned(); } operator mpty*() { return smhldr_ptr->as_raw_ptr_unowned(); } + + // clang-format on }; template <> struct type_caster> : smart_holder_type_caster_load { static constexpr auto name = _>(); - static handle cast(const std::shared_ptr& /*src*/, + static handle cast(const std::shared_ptr & /*src*/, return_value_policy /*policy*/, handle /*parent*/) { return str("cast_shmp").release(); } - template using cast_op_type = std::shared_ptr; + template + using cast_op_type = std::shared_ptr; operator std::shared_ptr() { return smhldr_ptr->as_shared_ptr(); } }; @@ -135,13 +138,14 @@ template <> struct type_caster> : smart_holder_type_caster_load { static constexpr auto name = _>(); - static handle cast(const std::shared_ptr& /*src*/, + static handle cast(const std::shared_ptr & /*src*/, return_value_policy /*policy*/, handle /*parent*/) { return str("cast_shcp").release(); } - template using cast_op_type = std::shared_ptr; + template + using cast_op_type = std::shared_ptr; operator std::shared_ptr() { return smhldr_ptr->as_shared_ptr(); } }; @@ -150,13 +154,13 @@ template <> struct type_caster> : smart_holder_type_caster_load { static constexpr auto name = _>(); - static handle cast(std::unique_ptr&& /*src*/, - return_value_policy /*policy*/, - handle /*parent*/) { + static handle + cast(std::unique_ptr && /*src*/, return_value_policy /*policy*/, handle /*parent*/) { return str("cast_uqmp").release(); } - template using cast_op_type = std::unique_ptr; + template + using cast_op_type = std::unique_ptr; operator std::unique_ptr() { return smhldr_ptr->as_unique_ptr(); } }; @@ -165,19 +169,20 @@ template <> struct type_caster> : smart_holder_type_caster_load { static constexpr auto name = _>(); - static handle cast(std::unique_ptr&& /*src*/, + static handle cast(std::unique_ptr && /*src*/, return_value_policy /*policy*/, handle /*parent*/) { return str("cast_uqcp").release(); } - template using cast_op_type = std::unique_ptr; + template + using cast_op_type = std::unique_ptr; operator std::unique_ptr() { return smhldr_ptr->as_unique_ptr(); } }; -} // namespace detail -} // namespace pybind11 +} // namespace detail +} // namespace pybind11 namespace pybind11_tests { namespace classh_wip { @@ -185,11 +190,11 @@ namespace classh_wip { TEST_SUBMODULE(classh_wip, m) { namespace py = pybind11; - py::classh(m, "mpty") - .def(py::init<>()) - .def(py::init([](const std::string& mtxt) { - mpty obj; obj.mtxt = mtxt; return obj; })) - ; + py::classh(m, "mpty").def(py::init<>()).def(py::init([](const std::string &mtxt) { + mpty obj; + obj.mtxt = mtxt; + return obj; + })); m.def("rtrn_mpty_valu", rtrn_mpty_valu); m.def("rtrn_mpty_rref", rtrn_mpty_rref); @@ -218,5 +223,5 @@ TEST_SUBMODULE(classh_wip, m) { m.def("pass_mpty_uqcp", pass_mpty_uqcp); } -} // namespace classh_wip -} // namespace pybind11_tests +} // namespace classh_wip +} // namespace pybind11_tests