diff --git a/src/BroList.h b/src/BroList.h index c7637b6bd0..a37f40d84a 100644 --- a/src/BroList.h +++ b/src/BroList.h @@ -23,4 +23,4 @@ class Attr; typedef PList attr_list; class Timer; -typedef PList timer_list; +typedef PList timer_list; diff --git a/src/List.cc b/src/List.cc index 1f2e4ec410..c19353b341 100644 --- a/src/List.cc +++ b/src/List.cc @@ -117,7 +117,7 @@ TEST_CASE("plists") TEST_CASE("unordered list operation") { - List list({1, 2, 3, 4}); + List list({1, 2, 3, 4}); CHECK(list.size() == 4); // An unordered list doesn't maintain the ordering of the elements when diff --git a/src/List.h b/src/List.h index 55256b35fb..c6d0902013 100644 --- a/src/List.h +++ b/src/List.h @@ -29,9 +29,9 @@ // TODO: this can be removed in v3.1 when List::sort() is removed typedef int (*list_cmp_func)(const void* v1, const void* v2); -enum list_order { LIST_ORDERED, LIST_UNORDERED }; +enum class ListOrder : int { ORDERED, UNORDERED }; -template +template class List { public: @@ -216,7 +216,7 @@ public: // For data where we don't care about ordering, we don't care about keeping // the list in the same order when removing an element. Just swap the last // element with the element being removed. - if ( Order == LIST_ORDERED ) + if constexpr ( Order == ListOrder::ORDERED ) { --num_entries; @@ -252,16 +252,16 @@ public: T replace(int ent_index, const T& new_ent) // replace entry #i with a new value { if ( ent_index < 0 ) - return get_default_value(); + return T{}; - T old_ent = get_default_value(); + T old_ent{}; if ( ent_index > num_entries - 1 ) { // replacement beyond the end of the list resize(ent_index + 1); for ( int i = num_entries; i < max_entries; ++i ) - entries[i] = get_default_value(); + entries[i] = T{}; num_entries = max_entries; } else @@ -299,20 +299,6 @@ public: protected: - T get_default_value() - { - if constexpr ( std::is_pointer_v ) - return nullptr; - else if constexpr ( std::is_integral_v ) - return 0; - else if constexpr ( std::is_floating_point_v ) - return 0.0; - else - // TODO: Should this return an error at compile time that we don't - // know what this type is? - return T(); - } - // This could essentially be an std::vector if we wanted. Some // reasons to maybe not refactor to use std::vector ? // @@ -344,7 +330,7 @@ protected: // Specialization of the List class to store pointers of a type. -template +template using PList = List; // Popular type of list: list of strings.