From d27bbb4648d8df9c5d85d7111138373c3426f0d7 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Tue, 6 Sep 2016 13:57:00 +0200 Subject: [PATCH] Allow construction from ranges of intervals This allows constructing interval_map and interval_set as const variables without having to resort to constructor functions. E.g. boost::assign::list_of can now be used to fill them. --- include/boost/icl/interval_map.hpp | 9 +++++++++ include/boost/icl/interval_set.hpp | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/boost/icl/interval_map.hpp b/include/boost/icl/interval_map.hpp index ffddc3e..8ab52cc 100644 --- a/include/boost/icl/interval_map.hpp +++ b/include/boost/icl/interval_map.hpp @@ -92,6 +92,15 @@ class interval_map: explicit interval_map(const value_type& value_pair): base_type() { this->add(value_pair); } + /// Constructor for a range of intervals + template + interval_map(InputIterator first, const InputIterator last) + { + for (; first != last; ++first) + { + this->add(*first); + } + } /// Assignment from a base interval_map. template diff --git a/include/boost/icl/interval_set.hpp b/include/boost/icl/interval_set.hpp index 22f97a4..dc7642d 100644 --- a/include/boost/icl/interval_set.hpp +++ b/include/boost/icl/interval_set.hpp @@ -115,6 +115,16 @@ class interval_set: this->add(itv); } + /// Constructor for a range of intervals + template + interval_set(InputIterator first, const InputIterator last) + { + for (; first != last; ++first) + { + this->add(*first); + } + } + /// Assignment from a base interval_set. template void assign(const interval_base_set& src)