]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: add interval_map initializer list constructor
authorJason Dillaman <dillaman@redhat.com>
Wed, 30 Sep 2020 17:30:42 +0000 (13:30 -0400)
committerJason Dillaman <dillaman@redhat.com>
Tue, 13 Oct 2020 12:40:05 +0000 (08:40 -0400)
This simplifies unit test cases by allowing interval_maps to be
trivially constructed with pre-populated expectations.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/common/interval_map.h

index 320c884373275a30e930a203ef3eb0789cca48a8..65a89e211f2b1d37f4dd22bc5b409452e04493d9 100644 (file)
@@ -16,6 +16,7 @@
 #define INTERVAL_MAP_H
 
 #include "include/interval_set.h"
+#include <initializer_list>
 
 template <typename K, typename V, typename S>
 /**
@@ -101,6 +102,13 @@ class interval_map {
     }
   }
 public:
+  interval_map() = default;
+  interval_map(std::initializer_list<typename map::value_type> l) {
+    for (auto& v : l) {
+      insert(v.first, v.second.first, v.second.second);
+    }
+  }
+
   interval_map intersect(K off, K len) const {
     interval_map ret;
     auto limits = get_range(off, len);