diff --git a/include/iris/interval_set.hpp b/include/iris/interval_set.hpp index d7797e6..fe798ed 100644 --- a/include/iris/interval_set.hpp +++ b/include/iris/interval_set.hpp @@ -88,7 +88,16 @@ class interval_set constexpr interval_set() = default; - constexpr explicit interval_set(std::initializer_list il) + // Unlike `std::vector` etc., we allow construction from a single `IntervalT`: + // an interval is not an element but a convex set of offsets. + constexpr explicit interval_set(IntervalT const& iv) + { + if (!iv.empty()) { + map_.emplace(iv.lower, iv.upper); + } + } + + constexpr interval_set(std::initializer_list il) { auto it = il.begin(); if (it == il.end()) return; diff --git a/test/interval_set.cpp b/test/interval_set.cpp index ff8c1e4..8950834 100644 --- a/test/interval_set.cpp +++ b/test/interval_set.cpp @@ -35,8 +35,10 @@ TEST_CASE("interval_set: type_traits") STATIC_CHECK(std::is_copy_assignable_v); STATIC_CHECK(std::is_nothrow_swappable_v); - STATIC_CHECK(!std::is_constructible_v>); + STATIC_CHECK(std::is_constructible_v>); + STATIC_CHECK(!std::is_convertible_v, IVS>); STATIC_CHECK(std::is_constructible_v>>); + STATIC_CHECK(std::is_convertible_v>, IVS>); } TEST_CASE("interval_set: construction")