diff --git a/src/blackmisc/collection.h b/src/blackmisc/collection.h index d842b2038..7df5c1f8f 100644 --- a/src/blackmisc/collection.h +++ b/src/blackmisc/collection.h @@ -17,6 +17,7 @@ #include #include #include +#include namespace BlackMisc { @@ -33,6 +34,12 @@ namespace BlackMisc //! Insert a new value into the set. typename QMap::iterator insert(const T &value) { return QMap::insert(value, value); } + + //! Default constructor. + QOrderedSet() {} + + //! Initializer list constructor. + QOrderedSet(std::initializer_list il) { for (const auto &v : il) { insert(v); } } }; /*! @@ -64,6 +71,11 @@ namespace BlackMisc */ CCollection() : m_pimpl(new Pimpl>(QOrderedSet())) {} + /*! + * \brief Initializer list constructor. + */ + CCollection(std::initializer_list il) : m_pimpl(new Pimpl>(QOrderedSet(il))) {} + /*! * \brief Copy constructor. */ diff --git a/src/blackmisc/dictionary.h b/src/blackmisc/dictionary.h index aae64115b..7d1012de7 100644 --- a/src/blackmisc/dictionary.h +++ b/src/blackmisc/dictionary.h @@ -10,6 +10,7 @@ #include "iterator.h" #include #include +#include namespace BlackMisc { @@ -240,6 +241,9 @@ namespace BlackMisc //! Default constructor. CDictionary() {} + //! Initializer list constructor. + CDictionary(std::initializer_list> il) : m_impl(il) {} + //! Copy constructor CDictionary(const CDictionary &) = default; diff --git a/src/blackmisc/range.h b/src/blackmisc/range.h index 1e38a4ddd..ed5d802d4 100644 --- a/src/blackmisc/range.h +++ b/src/blackmisc/range.h @@ -15,9 +15,20 @@ #include #include #include +#include namespace BlackMisc { + namespace Private + { + // Trait to exclude std::initializer_list from the overload set of CRange conversion operators using SFINAE. + // Needed to workaround a bug in MSVC whereby it considers the copy constructor and initializer list constructor + // of a container to be ambiguous when converting from a CRange. + //! \private + template struct is_initializer_list : public std::false_type {}; + //! \private + template struct is_initializer_list> : public std::true_type {}; + } template class CRange; @@ -135,7 +146,8 @@ namespace BlackMisc //! @} //! Implicit conversion to any container of value_type which supports push_back. This will copy elements. - template ::value>::type> + template ::value && + std::is_convertible::value>::type> operator T() const { T container; diff --git a/src/blackmisc/sequence.h b/src/blackmisc/sequence.h index e9518dab2..b56776489 100644 --- a/src/blackmisc/sequence.h +++ b/src/blackmisc/sequence.h @@ -17,6 +17,7 @@ #include #include #include +#include namespace BlackMisc { @@ -50,6 +51,11 @@ namespace BlackMisc */ CSequence() : m_pimpl(new Pimpl>(QList())) {} + /*! + * \brief Initializer list constructor. + */ + CSequence(std::initializer_list il) : m_pimpl(new Pimpl>(QList(il))) {} + /*! * \brief Copy constructor. */