From b342c37388177067db9e8ba609aacc119c24b1a4 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Thu, 10 Sep 2020 22:57:10 -0400 Subject: [PATCH] style: clang-tidy: modernize-use-using --- .clang-tidy | 1 + include/pybind11/chrono.h | 6 +++--- include/pybind11/detail/common.h | 18 +++++++++--------- include/pybind11/numpy.h | 2 +- include/pybind11/pybind11.h | 2 +- tests/test_class.cpp | 16 ++++++++-------- 6 files changed, 23 insertions(+), 22 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 6df242d94..294a1902f 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -5,6 +5,7 @@ Checks: ' llvm-namespace-comment, modernize-use-override, readability-container-size-empty, +modernize-use-using, ' HeaderFilterRegex: 'pybind11/.*h' diff --git a/include/pybind11/chrono.h b/include/pybind11/chrono.h index ac3d34e06..cbe9acec3 100644 --- a/include/pybind11/chrono.h +++ b/include/pybind11/chrono.h @@ -33,9 +33,9 @@ PYBIND11_NAMESPACE_BEGIN(detail) template class duration_caster { public: typedef typename type::rep rep; - typedef typename type::period period; + using period = typename type::period; - typedef std::chrono::duration> days; + using days = std::chrono::duration>; bool load(handle src, bool) { using namespace std::chrono; @@ -98,7 +98,7 @@ public: // This is for casting times on the system clock into datetime.datetime instances template class type_caster> { public: - typedef std::chrono::time_point type; + using type = std::chrono::time_point; bool load(handle src, bool) { using namespace std::chrono; diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index 7d6530cc8..68036c73b 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -537,17 +537,17 @@ template class... Predicates> using satisfies_none_of /// Strip the class from a method type template struct remove_class { }; -template struct remove_class { typedef R type(A...); }; -template struct remove_class { typedef R type(A...); }; +template struct remove_class { using type = R (A...); }; +template struct remove_class { using type = R (A...); }; /// Helper template to strip away type modifiers -template struct intrinsic_type { typedef T type; }; -template struct intrinsic_type { typedef typename intrinsic_type::type type; }; -template struct intrinsic_type { typedef typename intrinsic_type::type type; }; -template struct intrinsic_type { typedef typename intrinsic_type::type type; }; -template struct intrinsic_type { typedef typename intrinsic_type::type type; }; -template struct intrinsic_type { typedef typename intrinsic_type::type type; }; -template struct intrinsic_type { typedef typename intrinsic_type::type type; }; +template struct intrinsic_type { using type = T; }; +template struct intrinsic_type { using type = typename intrinsic_type::type; }; +template struct intrinsic_type { using type = typename intrinsic_type::type; }; +template struct intrinsic_type { using type = typename intrinsic_type::type; }; +template struct intrinsic_type { using type = typename intrinsic_type::type; }; +template struct intrinsic_type { using type = typename intrinsic_type::type; }; +template struct intrinsic_type { using type = typename intrinsic_type::type; }; template using intrinsic_t = typename intrinsic_type::type; /// Helper type to replace 'void' in some expressions diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index c0b38ce20..7c3ac121b 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -281,7 +281,7 @@ template struct is_complex : std::false_type { }; template struct is_complex> : std::true_type { }; template struct array_info_scalar { - typedef T type; + using type = T; static constexpr bool is_array = false; static constexpr bool is_empty = false; static constexpr auto extents = _(""); diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 9f1736fd7..c6334fbbb 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1789,7 +1789,7 @@ template ()).first), typename... Extra> iterator make_key_iterator(Iterator first, Sentinel last, Extra &&... extra) { - typedef detail::iterator_state state; + using state = detail::iterator_state; if (!detail::get_type_info(typeid(state), false)) { class_(handle(), "iterator", pybind11::module_local()) diff --git a/tests/test_class.cpp b/tests/test_class.cpp index e7eaa83ea..4dd4941f3 100644 --- a/tests/test_class.cpp +++ b/tests/test_class.cpp @@ -425,14 +425,14 @@ template class BreaksBase { public: }; template class BreaksTramp : public BreaksBase {}; // These should all compile just fine: -typedef py::class_, std::unique_ptr>, BreaksTramp<1>> DoesntBreak1; -typedef py::class_, BreaksTramp<2>, std::unique_ptr>> DoesntBreak2; -typedef py::class_, std::unique_ptr>> DoesntBreak3; -typedef py::class_, BreaksTramp<4>> DoesntBreak4; -typedef py::class_> DoesntBreak5; -typedef py::class_, std::shared_ptr>, BreaksTramp<6>> DoesntBreak6; -typedef py::class_, BreaksTramp<7>, std::shared_ptr>> DoesntBreak7; -typedef py::class_, std::shared_ptr>> DoesntBreak8; +using DoesntBreak1 = py::class_, std::unique_ptr>, BreaksTramp<1>>; +using DoesntBreak2 = py::class_, BreaksTramp<2>, std::unique_ptr>>; +using DoesntBreak3 = py::class_, std::unique_ptr>>; +using DoesntBreak4 = py::class_, BreaksTramp<4>>; +using DoesntBreak5 = py::class_>; +using DoesntBreak6 = py::class_, std::shared_ptr>, BreaksTramp<6>>; +using DoesntBreak7 = py::class_, BreaksTramp<7>, std::shared_ptr>>; +using DoesntBreak8 = py::class_, std::shared_ptr>>; #define CHECK_BASE(N) static_assert(std::is_same>::value, \ "DoesntBreak" #N " has wrong type!") CHECK_BASE(1); CHECK_BASE(2); CHECK_BASE(3); CHECK_BASE(4); CHECK_BASE(5); CHECK_BASE(6); CHECK_BASE(7); CHECK_BASE(8);