mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
refs #311 added initializer_list constructors in containers
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include <type_traits>
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
#include <initializer_list>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -33,6 +34,12 @@ namespace BlackMisc
|
||||
|
||||
//! Insert a new value into the set.
|
||||
typename QMap<T, T>::iterator insert(const T &value) { return QMap<T, T>::insert(value, value); }
|
||||
|
||||
//! Default constructor.
|
||||
QOrderedSet() {}
|
||||
|
||||
//! Initializer list constructor.
|
||||
QOrderedSet(std::initializer_list<T> il) { for (const auto &v : il) { insert(v); } }
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -64,6 +71,11 @@ namespace BlackMisc
|
||||
*/
|
||||
CCollection() : m_pimpl(new Pimpl<QOrderedSet<T>>(QOrderedSet<T>())) {}
|
||||
|
||||
/*!
|
||||
* \brief Initializer list constructor.
|
||||
*/
|
||||
CCollection(std::initializer_list<T> il) : m_pimpl(new Pimpl<QOrderedSet<T>>(QOrderedSet<T>(il))) {}
|
||||
|
||||
/*!
|
||||
* \brief Copy constructor.
|
||||
*/
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "iterator.h"
|
||||
#include <QHash>
|
||||
#include <utility>
|
||||
#include <initializer_list>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -240,6 +241,9 @@ namespace BlackMisc
|
||||
//! Default constructor.
|
||||
CDictionary() {}
|
||||
|
||||
//! Initializer list constructor.
|
||||
CDictionary(std::initializer_list<std::pair<Key, Value>> il) : m_impl(il) {}
|
||||
|
||||
//! Copy constructor
|
||||
CDictionary(const CDictionary &) = default;
|
||||
|
||||
|
||||
@@ -15,9 +15,20 @@
|
||||
#include <algorithm>
|
||||
#include <type_traits>
|
||||
#include <iterator>
|
||||
#include <initializer_list>
|
||||
|
||||
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 <class T> struct is_initializer_list : public std::false_type {};
|
||||
//! \private
|
||||
template <class T> struct is_initializer_list<std::initializer_list<T>> : public std::true_type {};
|
||||
}
|
||||
|
||||
template <class> 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 <class T, class = typename std::enable_if<std::is_convertible<value_type, typename T::value_type>::value>::type>
|
||||
template <class T, class = typename std::enable_if<! Private::is_initializer_list<T>::value &&
|
||||
std::is_convertible<value_type, typename T::value_type>::value>::type>
|
||||
operator T() const
|
||||
{
|
||||
T container;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <type_traits>
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
#include <initializer_list>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -50,6 +51,11 @@ namespace BlackMisc
|
||||
*/
|
||||
CSequence() : m_pimpl(new Pimpl<QList<T>>(QList<T>())) {}
|
||||
|
||||
/*!
|
||||
* \brief Initializer list constructor.
|
||||
*/
|
||||
CSequence(std::initializer_list<T> il) : m_pimpl(new Pimpl<QList<T>>(QList<T>(il))) {}
|
||||
|
||||
/*!
|
||||
* \brief Copy constructor.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user