Skip to content

Commit

Permalink
Merge pull request hove-io#102 from AzHicham/clang-tidy-modernize
Browse files Browse the repository at this point in the history
Clang-tidy modernize
  • Loading branch information
HichamAz authored Jul 30, 2021
2 parents 8cb4dca + 6c45cf7 commit d85d6f6
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 68 deletions.
2 changes: 1 addition & 1 deletion coord_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class wrong_coordinate : public std::runtime_error {
public:
wrong_coordinate(const std::string& what) : std::runtime_error(what) {}
wrong_coordinate(const wrong_coordinate&) = default;
virtual ~wrong_coordinate() noexcept;
~wrong_coordinate() noexcept override;
};

extern const boost::regex coord_regex;
Expand Down
2 changes: 1 addition & 1 deletion deadline.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DeadlineExpired : public recoverable_exception {

public:
DeadlineExpired(const DeadlineExpired& o) = default;
virtual ~DeadlineExpired();
~DeadlineExpired() override;
};

class Deadline {
Expand Down
9 changes: 5 additions & 4 deletions exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ www.navitia.io

#include <string>
#include <exception>
#include <utility>

namespace navitia {
class exception : public std::exception {
Expand All @@ -41,13 +42,13 @@ class exception : public std::exception {
std::string _backtrace;

public:
exception(const std::string& msg) : msg(msg), _backtrace(get_backtrace()) {}
exception(std::string msg) : msg(std::move(msg)), _backtrace(get_backtrace()) {}
exception() = default;
exception(const exception&) = default;
exception& operator=(const exception&) = default;
virtual ~exception() noexcept;
~exception() noexcept override;

const char* what() const noexcept { return msg.c_str(); }
const char* what() const noexcept override { return msg.c_str(); }
const std::string& backtrace() const noexcept { return _backtrace; }
};

Expand All @@ -62,6 +63,6 @@ struct recoverable_exception : public exception {
recoverable_exception() = default;
recoverable_exception(const recoverable_exception&) = default;
recoverable_exception& operator=(const recoverable_exception&) = default;
virtual ~recoverable_exception() noexcept;
~recoverable_exception() noexcept override;
};
} // namespace navitia
30 changes: 15 additions & 15 deletions flat_enum_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct get_enum_type {
#else
template <typename Enum>
struct get_enum_type {
typedef int type;
using type = int;
};
#endif

Expand Down Expand Up @@ -92,9 +92,9 @@ class flat_enum_map_iterator;
*/
template <typename EnumKey, typename Value>
struct flat_enum_map {
typedef std::array<Value, enum_size_trait<EnumKey>::size()> underlying_container;
typedef flat_enum_map_iterator<EnumKey, Value> iterator;
typedef flat_enum_map_iterator<EnumKey, const Value> const_iterator;
using underlying_container = std::array<Value, enum_size_trait<EnumKey>::size()>;
using iterator = flat_enum_map_iterator<EnumKey, Value>;
using const_iterator = flat_enum_map_iterator<EnumKey, const Value>;

underlying_container array;

Expand Down Expand Up @@ -136,11 +136,11 @@ struct flat_enum_map {
template <typename Enum>
class enum_iterator
: public boost::iterator_facade<enum_iterator<Enum>, Enum, boost::random_access_traversal_tag, Enum> {
typedef typename get_enum_type<Enum>::type underlying_type;
using underlying_type = typename get_enum_type<Enum>::type;
underlying_type _it;

public:
typedef std::make_signed<typename get_enum_type<Enum>::type> difference_type;
using difference_type = std::make_signed<typename get_enum_type<Enum>::type>;
enum_iterator() : _it(enum_size_trait<Enum>::size()) {}
enum_iterator(const Enum& e) : _it(static_cast<underlying_type>(e)) {}
enum_iterator(const underlying_type& i) : _it(i) {}
Expand All @@ -156,27 +156,27 @@ class enum_iterator

template <typename Enum>
boost::iterator_range<enum_iterator<Enum>> enum_range() {
typedef enum_iterator<Enum> it;
using it = enum_iterator<Enum>;
return boost::make_iterator_range(it(get_first_elt<Enum>()), it());
}

template <typename Enum>
boost::iterator_range<boost::reverse_iterator<enum_iterator<Enum>>> reverse_enum_range() {
typedef enum_iterator<Enum> it;
typedef boost::reverse_iterator<it> rit;
using it = enum_iterator<Enum>;
using rit = boost::reverse_iterator<it>;
return boost::make_iterator_range(rit(it(enum_size_trait<Enum>::size())), rit(it(0)));
}

template <typename Enum>
boost::iterator_range<enum_iterator<Enum>> enum_range_from(Enum e) {
typedef enum_iterator<Enum> it;
using it = enum_iterator<Enum>;
return boost::make_iterator_range(it(e), it());
}

template <typename Enum>
boost::iterator_range<boost::reverse_iterator<enum_iterator<Enum>>> reverse_enum_range_from(Enum e) {
typedef enum_iterator<Enum> it;
typedef boost::reverse_iterator<it> rit;
using it = enum_iterator<Enum>;
using rit = boost::reverse_iterator<it>;
using e_type = typename get_enum_type<Enum>::type;
return boost::make_iterator_range(rit(it(static_cast<Enum>(static_cast<e_type>(e) + 1))), rit(it(0)));
}
Expand All @@ -186,13 +186,13 @@ class flat_enum_map_iterator : public boost::iterator_facade<flat_enum_map_itera
std::pair<EnumKey, Value&>,
boost::random_access_traversal_tag,
std::pair<EnumKey, Value&>> {
typedef flat_enum_map<EnumKey, Value> enum_map;
typedef typename flat_enum_map_iterator<EnumKey, Value>::difference_type difference_type;
using enum_map = flat_enum_map<EnumKey, Value>;
using difference_type = typename flat_enum_map_iterator<EnumKey, Value>::difference_type;
typename enum_map::underlying_container::iterator _iterator;
enum_iterator<EnumKey> _enum_iterator;

public:
flat_enum_map_iterator() {}
flat_enum_map_iterator() = default;
flat_enum_map_iterator(typename enum_map::underlying_container::iterator it) : _iterator(it) {}
flat_enum_map_iterator(typename enum_map::underlying_container::iterator it, EnumKey e)
: _iterator(it), _enum_iterator(e) {}
Expand Down
4 changes: 2 additions & 2 deletions functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void sort_and_truncate(Vector& input, size_t nbmax, Cmp cmp) {
*/
template <typename Elem, typename Cmp>
void sort_and_truncate(typename google::protobuf::RepeatedPtrField<Elem>& input, size_t nbmax, Cmp cmp) {
typedef typename google::protobuf::RepeatedPtrField<Elem> Vector;
using Vector = typename google::protobuf::RepeatedPtrField<Elem>;
typename Vector::iterator middle_iterator;
if (nbmax < size_t(input.size()))
middle_iterator = input.begin() + nbmax;
Expand All @@ -182,7 +182,7 @@ void sort_and_truncate(typename google::protobuf::RepeatedPtrField<Elem>& input,
*/
template <typename Elem, typename Cmp>
void sort_and_truncate(typename std::vector<Elem>& input, size_t nbmax, Cmp cmp) {
typedef typename std::vector<Elem> Vector;
using Vector = typename std::vector<Elem>;
typename Vector::iterator middle_iterator;
if (nbmax < size_t(input.size())) {
middle_iterator = input.begin() + nbmax;
Expand Down
22 changes: 11 additions & 11 deletions idx_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ www.navitia.io

namespace navitia {

typedef uint32_t idx_t;
using idx_t = uint32_t;
const idx_t invalid_idx = std::numeric_limits<idx_t>::max();

// Strong typing of index with a phantom type!
Expand All @@ -60,10 +60,10 @@ class IdxMapIterator : public boost::iterator_facade<IdxMapIterator<K, I>,
boost::random_access_traversal_tag,
std::pair<const K, typename std::iterator_traits<I>::reference> > {
public:
typedef typename std::iterator_traits<I> traits;
typedef typename traits::difference_type difference_type;
using traits = typename std::iterator_traits<I>;
using difference_type = typename traits::difference_type;

inline IdxMapIterator() {}
inline IdxMapIterator() = default;
inline IdxMapIterator(const idx_t& i, I it) : idx(i), iterator(it) {}

private:
Expand Down Expand Up @@ -92,13 +92,13 @@ class IdxMapIterator : public boost::iterator_facade<IdxMapIterator<K, I>,
// A HashMap with optimal hash!
template <typename T, typename V>
struct IdxMap {
typedef Idx<T> key_type;
typedef V mapped_type;
typedef std::vector<V> container;
typedef IdxMapIterator<key_type, typename container::iterator> iterator;
typedef IdxMapIterator<key_type, typename container::const_iterator> const_iterator;
typedef boost::iterator_range<typename std::vector<V>::iterator> range;
typedef boost::iterator_range<typename std::vector<V>::const_iterator> const_range;
using key_type = Idx<T>;
using mapped_type = V;
using container = std::vector<V>;
using iterator = IdxMapIterator<key_type, typename container::iterator>;
using const_iterator = IdxMapIterator<key_type, typename container::const_iterator>;
using range = boost::iterator_range<typename std::vector<V>::iterator>;
using const_range = boost::iterator_range<typename std::vector<V>::const_iterator>;

inline IdxMap() = default;
inline IdxMap(const std::vector<T*>& c, const V& val = V()) : map(c.size(), val) {}
Expand Down
2 changes: 1 addition & 1 deletion lotus.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ www.navitia.io
struct LotusException : public std::exception {
std::string const message;
LotusException(std::string message) : message(std::move(message)) {}
virtual const char* what() const noexcept override;
const char* what() const noexcept override;
};

struct Lotus {
Expand Down
30 changes: 15 additions & 15 deletions lru.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ template <typename F>
class Lru {
private:
typedef typename boost::remove_cv<typename boost::remove_reference<typename F::argument_type>::type>::type key_type;
typedef
typename boost::remove_cv<typename boost::remove_reference<typename F::result_type>::type>::type mapped_type;
typedef std::pair<const key_type, mapped_type> value_type;
typedef boost::multi_index_container<
using mapped_type =
typename boost::remove_cv<typename boost::remove_reference<typename F::result_type>::type>::type;
using value_type = std::pair<const key_type, mapped_type>;
using Cache = boost::multi_index_container<
value_type,
boost::multi_index::indexed_by<boost::multi_index::sequenced<>,
boost::multi_index::ordered_unique<
boost::multi_index::member<value_type, const key_type, &value_type::first>>>>
Cache;
boost::multi_index::indexed_by<
boost::multi_index::sequenced<>,
boost::multi_index::ordered_unique<
boost::multi_index::member<value_type, const key_type, &value_type::first>>>>;

// the encapsulate function
F f;
Expand All @@ -89,8 +89,8 @@ class Lru {
friend struct ConcurrentLru;

public:
typedef mapped_type const& result_type;
typedef typename F::argument_type argument_type;
using result_type = const mapped_type&;
using argument_type = typename F::argument_type;

Lru(F fun, size_t max = 10) : f(std::move(fun)), max_cache(max) {
if (max < 1) {
Expand Down Expand Up @@ -134,8 +134,8 @@ class Lru {
}
};
template <typename F>
inline Lru<F> make_lru(F fun, size_t max = 10) {
return Lru<F>(std::move(fun), max);
inline Lru<F> make_lru(F&& fun, size_t max = 10) {
return Lru<F>(std::forward<F>(fun), max);
}

template <typename F>
Expand Down Expand Up @@ -167,7 +167,7 @@ struct ConcurrentLru {
using argument_type = typename SharedPtrF::argument_type;

ConcurrentLru(F fun, size_t max = 10) : lru(SharedPtrF{std::move(fun)}, max) {}
ConcurrentLru(ConcurrentLru&&) = default; // needed by old version of gcc
ConcurrentLru(ConcurrentLru&&) = default; // NOLINT // needed by old version of gcc

result_type operator()(argument_type arg) const {
typename SharedPtrF::result_type future;
Expand Down Expand Up @@ -195,8 +195,8 @@ struct ConcurrentLru {
}
};
template <typename F>
inline ConcurrentLru<F> make_concurrent_lru(F fun, size_t max = 10) {
return ConcurrentLru<F>(std::move(fun), max);
inline ConcurrentLru<F> make_concurrent_lru(F&& fun, size_t max = 10) {
return ConcurrentLru<F>(std::forward<F>(fun), max);
}

} // namespace navitia
6 changes: 3 additions & 3 deletions map_find.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ namespace utils {
template <class Map>
class MapFind {
public:
typedef typename Map::key_type KeyType;
typedef typename Map::mapped_type ValueType;
typedef ValueType const* ConstPtrValueType;
using KeyType = typename Map::key_type;
using ValueType = typename Map::mapped_type;
using ConstPtrValueType = const ValueType*;

/**
* @brief Create a MapFind object on a map, no find is performed until find() is called.
Expand Down
9 changes: 5 additions & 4 deletions multi_obj_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ www.navitia.io

#include <list>
#include <cstddef>
#include <utility>

template <typename Obj>
struct DefaultParetoFrontVisitor {
Expand All @@ -53,14 +54,14 @@ struct DefaultParetoFrontVisitor {
template <typename Obj, typename Dominator, typename Visitor = DefaultParetoFrontVisitor<Obj>>
class ParetoFront {
public:
typedef std::list<Obj> Pool;
typedef typename Pool::value_type value_type;
typedef typename Pool::const_iterator const_iterator;
using Pool = std::list<Obj>;
using value_type = typename Pool::value_type;
using const_iterator = typename Pool::const_iterator;

Visitor visitor;

ParetoFront() = default;
explicit ParetoFront(Dominator x) : dominate(x) {}
explicit ParetoFront(Dominator x) : dominate(std::move(x)) {}
explicit ParetoFront(Dominator x, Visitor v) : dominate(x), visitor(v) {}

bool add(const Obj& obj);
Expand Down
2 changes: 1 addition & 1 deletion tests/lru_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ www.navitia.io

struct Fun {
typedef int const& argument_type;
typedef int result_type;
using result_type = int;
size_t& nb_call;
Fun(size_t& nb): nb_call(nb) {}
int operator()(const int& i) const { ++nb_call; return i * 2; }
Expand Down
5 changes: 3 additions & 2 deletions tests/map_find_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ www.navitia.io
#include <map>
#include <unordered_map>
#include <string>
#include <utility>

using namespace navitia::utils;
using std::string;
Expand Down Expand Up @@ -105,14 +106,14 @@ BOOST_FIXTURE_TEST_CASE(should_not_copy_value_object_when_queried, MapFindFixtur

struct NonCopyable {
const string str;
NonCopyable(const string & str): str(str) {}
NonCopyable(string str) : str(std::move(str)) {}

/// We remove the copy semantic to make sure objects are not duplicated along the way
NonCopyable(const NonCopyable &) = delete;
NonCopyable& operator=(const NonCopyable &) = delete;

/// we only keep the move construction semantic to emplace into the map
NonCopyable(NonCopyable && rhs): str(std::move(rhs.str)) {}
NonCopyable(NonCopyable&& rhs) noexcept : str(std::move(rhs.str)) {}
NonCopyable& operator=(NonCopyable && rhs) = delete;
};

Expand Down
4 changes: 2 additions & 2 deletions tests/utils_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,11 @@ BOOST_AUTO_TEST_CASE(natural_sort_test2) {

struct MockedContainerWithFind {
struct iterator{};
iterator end() const{return iterator();}
iterator end() const { return {}; }
bool mutable find_is_called{false};
iterator find(int) const {
find_is_called = true;
return iterator();
return {};
}
};

Expand Down
Loading

0 comments on commit d85d6f6

Please sign in to comment.