Skip to content

Commit b342c37

Browse files
committed
style: clang-tidy: modernize-use-using
1 parent 96e6a8d commit b342c37

File tree

6 files changed

+23
-22
lines changed

6 files changed

+23
-22
lines changed

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Checks: '
55
llvm-namespace-comment,
66
modernize-use-override,
77
readability-container-size-empty,
8+
modernize-use-using,
89
'
910

1011
HeaderFilterRegex: 'pybind11/.*h'

include/pybind11/chrono.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ PYBIND11_NAMESPACE_BEGIN(detail)
3333
template <typename type> class duration_caster {
3434
public:
3535
typedef typename type::rep rep;
36-
typedef typename type::period period;
36+
using period = typename type::period;
3737

38-
typedef std::chrono::duration<uint_fast32_t, std::ratio<86400>> days;
38+
using days = std::chrono::duration<uint_fast32_t, std::ratio<86400>>;
3939

4040
bool load(handle src, bool) {
4141
using namespace std::chrono;
@@ -98,7 +98,7 @@ template <typename type> class duration_caster {
9898
// This is for casting times on the system clock into datetime.datetime instances
9999
template <typename Duration> class type_caster<std::chrono::time_point<std::chrono::system_clock, Duration>> {
100100
public:
101-
typedef std::chrono::time_point<std::chrono::system_clock, Duration> type;
101+
using type = std::chrono::time_point<std::chrono::system_clock, Duration>;
102102
bool load(handle src, bool) {
103103
using namespace std::chrono;
104104

include/pybind11/detail/common.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -537,17 +537,17 @@ template <class T, template<class> class... Predicates> using satisfies_none_of
537537

538538
/// Strip the class from a method type
539539
template <typename T> struct remove_class { };
540-
template <typename C, typename R, typename... A> struct remove_class<R (C::*)(A...)> { typedef R type(A...); };
541-
template <typename C, typename R, typename... A> struct remove_class<R (C::*)(A...) const> { typedef R type(A...); };
540+
template <typename C, typename R, typename... A> struct remove_class<R (C::*)(A...)> { using type = R (A...); };
541+
template <typename C, typename R, typename... A> struct remove_class<R (C::*)(A...) const> { using type = R (A...); };
542542

543543
/// Helper template to strip away type modifiers
544-
template <typename T> struct intrinsic_type { typedef T type; };
545-
template <typename T> struct intrinsic_type<const T> { typedef typename intrinsic_type<T>::type type; };
546-
template <typename T> struct intrinsic_type<T*> { typedef typename intrinsic_type<T>::type type; };
547-
template <typename T> struct intrinsic_type<T&> { typedef typename intrinsic_type<T>::type type; };
548-
template <typename T> struct intrinsic_type<T&&> { typedef typename intrinsic_type<T>::type type; };
549-
template <typename T, size_t N> struct intrinsic_type<const T[N]> { typedef typename intrinsic_type<T>::type type; };
550-
template <typename T, size_t N> struct intrinsic_type<T[N]> { typedef typename intrinsic_type<T>::type type; };
544+
template <typename T> struct intrinsic_type { using type = T; };
545+
template <typename T> struct intrinsic_type<const T> { using type = typename intrinsic_type<T>::type; };
546+
template <typename T> struct intrinsic_type<T*> { using type = typename intrinsic_type<T>::type; };
547+
template <typename T> struct intrinsic_type<T&> { using type = typename intrinsic_type<T>::type; };
548+
template <typename T> struct intrinsic_type<T&&> { using type = typename intrinsic_type<T>::type; };
549+
template <typename T, size_t N> struct intrinsic_type<const T[N]> { using type = typename intrinsic_type<T>::type; };
550+
template <typename T, size_t N> struct intrinsic_type<T[N]> { using type = typename intrinsic_type<T>::type; };
551551
template <typename T> using intrinsic_t = typename intrinsic_type<T>::type;
552552

553553
/// Helper type to replace 'void' in some expressions

include/pybind11/numpy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ template <typename T> struct is_complex : std::false_type { };
281281
template <typename T> struct is_complex<std::complex<T>> : std::true_type { };
282282

283283
template <typename T> struct array_info_scalar {
284-
typedef T type;
284+
using type = T;
285285
static constexpr bool is_array = false;
286286
static constexpr bool is_empty = false;
287287
static constexpr auto extents = _("");

include/pybind11/pybind11.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1789,7 +1789,7 @@ template <return_value_policy Policy = return_value_policy::reference_internal,
17891789
typename KeyType = decltype((*std::declval<Iterator>()).first),
17901790
typename... Extra>
17911791
iterator make_key_iterator(Iterator first, Sentinel last, Extra &&... extra) {
1792-
typedef detail::iterator_state<Iterator, Sentinel, true, Policy> state;
1792+
using state = detail::iterator_state<Iterator, Sentinel, true, Policy>;
17931793

17941794
if (!detail::get_type_info(typeid(state), false)) {
17951795
class_<state>(handle(), "iterator", pybind11::module_local())

tests/test_class.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -425,14 +425,14 @@ template <int N> class BreaksBase { public:
425425
};
426426
template <int N> class BreaksTramp : public BreaksBase<N> {};
427427
// These should all compile just fine:
428-
typedef py::class_<BreaksBase<1>, std::unique_ptr<BreaksBase<1>>, BreaksTramp<1>> DoesntBreak1;
429-
typedef py::class_<BreaksBase<2>, BreaksTramp<2>, std::unique_ptr<BreaksBase<2>>> DoesntBreak2;
430-
typedef py::class_<BreaksBase<3>, std::unique_ptr<BreaksBase<3>>> DoesntBreak3;
431-
typedef py::class_<BreaksBase<4>, BreaksTramp<4>> DoesntBreak4;
432-
typedef py::class_<BreaksBase<5>> DoesntBreak5;
433-
typedef py::class_<BreaksBase<6>, std::shared_ptr<BreaksBase<6>>, BreaksTramp<6>> DoesntBreak6;
434-
typedef py::class_<BreaksBase<7>, BreaksTramp<7>, std::shared_ptr<BreaksBase<7>>> DoesntBreak7;
435-
typedef py::class_<BreaksBase<8>, std::shared_ptr<BreaksBase<8>>> DoesntBreak8;
428+
using DoesntBreak1 = py::class_<BreaksBase<1>, std::unique_ptr<BreaksBase<1>>, BreaksTramp<1>>;
429+
using DoesntBreak2 = py::class_<BreaksBase<2>, BreaksTramp<2>, std::unique_ptr<BreaksBase<2>>>;
430+
using DoesntBreak3 = py::class_<BreaksBase<3>, std::unique_ptr<BreaksBase<3>>>;
431+
using DoesntBreak4 = py::class_<BreaksBase<4>, BreaksTramp<4>>;
432+
using DoesntBreak5 = py::class_<BreaksBase<5>>;
433+
using DoesntBreak6 = py::class_<BreaksBase<6>, std::shared_ptr<BreaksBase<6>>, BreaksTramp<6>>;
434+
using DoesntBreak7 = py::class_<BreaksBase<7>, BreaksTramp<7>, std::shared_ptr<BreaksBase<7>>>;
435+
using DoesntBreak8 = py::class_<BreaksBase<8>, std::shared_ptr<BreaksBase<8>>>;
436436
#define CHECK_BASE(N) static_assert(std::is_same<typename DoesntBreak##N::type, BreaksBase<N>>::value, \
437437
"DoesntBreak" #N " has wrong type!")
438438
CHECK_BASE(1); CHECK_BASE(2); CHECK_BASE(3); CHECK_BASE(4); CHECK_BASE(5); CHECK_BASE(6); CHECK_BASE(7); CHECK_BASE(8);

0 commit comments

Comments
 (0)