mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-13 15:45:42 +08:00
Container classes: removed templated ctors and added static methods to replace them.
This resolves an issue with infinite recursion and stack overflows in MSVC2010. See also http://connect.microsoft.com/VisualStudio/feedback/details/522094/
This commit is contained in:
@@ -50,13 +50,6 @@ namespace BlackMisc
|
||||
*/
|
||||
CCollection() : m_pimpl(new Pimpl<QSet<T>>(QSet<T>())) {}
|
||||
|
||||
/*!
|
||||
* \brief Constructor.
|
||||
* \tparam C Becomes the collection's implementation type.
|
||||
* \param c Initial value for the collection; typically empty, but could contain elements.
|
||||
*/
|
||||
template <class C> CCollection(C c) : m_pimpl(new Pimpl<C>(std::move(c))) {}
|
||||
|
||||
/*!
|
||||
* \brief Copy constructor.
|
||||
* \param other
|
||||
@@ -69,13 +62,6 @@ namespace BlackMisc
|
||||
*/
|
||||
CCollection(CCollection &&other) : m_pimpl(other.m_pimpl.take()) {}
|
||||
|
||||
/*!
|
||||
* \brief Assignment.
|
||||
* \tparam C Becomes the collection's new implementation type.
|
||||
* \param c New value for the collection; typically empty, but could contain elements.
|
||||
*/
|
||||
template <class C> CCollection &operator =(C c) { m_pimpl.reset(new Pimpl<C>(std::move(c))); return *this; }
|
||||
|
||||
/*!
|
||||
* \brief Copy assignment.
|
||||
* \param other
|
||||
@@ -90,11 +76,19 @@ namespace BlackMisc
|
||||
*/
|
||||
CCollection &operator =(CCollection && other) { m_pimpl.reset(other.m_pimpl.take()); return *this; }
|
||||
|
||||
/*!
|
||||
* \brief Create a new collection with a specific implementation type.
|
||||
* \tparam C Becomes the collection's implementation type.
|
||||
* \param c Initial value for the collection; default is empty, but it could contain elements if desired. The value is copied.
|
||||
* \return
|
||||
*/
|
||||
template <class C> static CCollection fromImpl(C c = C()) { return CCollection(new Pimpl<C>(std::move(c))); }
|
||||
|
||||
/*!
|
||||
* \brief Change the implementation type but keep all the same elements, by copying them into the new implementation.
|
||||
* \tparam C Becomes the collection's new implementation type.
|
||||
*/
|
||||
template <class C> void changeImpl(C = C()) { CCollection c = C(); for (auto i = cbegin(); i != cend(); ++i) c.insert(*i); *this = std::move(c); }
|
||||
template <class C> void changeImpl(C = C()) { auto c = fromImpl(C()); for (auto i = cbegin(); i != cend(); ++i) c.insert(*i); *this = std::move(c); }
|
||||
|
||||
/*!
|
||||
* \brief Like changeImpl, but uses the implementation type of another collection.
|
||||
@@ -275,6 +269,8 @@ namespace BlackMisc
|
||||
typedef QScopedPointer<PimplBase> PimplPtr;
|
||||
PimplPtr m_pimpl;
|
||||
|
||||
CCollection(PimplBase *pimpl) : m_pimpl(pimpl) {} // private ctor used by fromImpl()
|
||||
|
||||
// using these methods to access m_pimpl.data() eases the cognitive burden of correctly forwarding const
|
||||
PimplBase *pimpl() { return m_pimpl.data(); }
|
||||
const PimplBase *pimpl() const { return m_pimpl.data(); }
|
||||
|
||||
@@ -50,13 +50,6 @@ namespace BlackMisc
|
||||
*/
|
||||
CSequence() : m_pimpl(new Pimpl<QList<T>>(QList<T>())) {}
|
||||
|
||||
/*!
|
||||
* \brief Constructor.
|
||||
* \tparam C Becomes the sequence's implementation type.
|
||||
* \param c Initial value for the sequence; typically empty, but could contain elements.
|
||||
*/
|
||||
template <class C> CSequence(C c) : m_pimpl(new Pimpl<C>(std::move(c))) {}
|
||||
|
||||
/*!
|
||||
* \brief Copy constructor.
|
||||
* \param other
|
||||
@@ -69,13 +62,6 @@ namespace BlackMisc
|
||||
*/
|
||||
CSequence(CSequence &&other) : m_pimpl(other.m_pimpl.take()) {}
|
||||
|
||||
/*!
|
||||
* \brief Assignment.
|
||||
* \tparam C Becomes the sequence's new implementation type.
|
||||
* \param c New value for the sequence; typically empty, but could contain elements.
|
||||
*/
|
||||
template <class C> CSequence &operator =(C c) { m_pimpl.reset(new Pimpl<C>(std::move(c))); return *this; }
|
||||
|
||||
/*!
|
||||
* \brief Copy assignment.
|
||||
* \param other
|
||||
@@ -90,11 +76,19 @@ namespace BlackMisc
|
||||
*/
|
||||
CSequence &operator =(CSequence &&other) { m_pimpl.reset(other.m_pimpl.take()); return *this; }
|
||||
|
||||
/*!
|
||||
* \brief Create a new sequence with a specific implementation type.
|
||||
* \tparam C Becomes the sequence's implementation type.
|
||||
* \param c Initial value for the sequence; default is empty, but it could contain elements if desired. The value is copied.
|
||||
* \return
|
||||
*/
|
||||
template <class C> static CSequence fromImpl(C c = C()) { return CSequence(new Pimpl<C>(std::move(c))); }
|
||||
|
||||
/*!
|
||||
* \brief Change the implementation type but keep all the same elements, by copying them into the new implementation.
|
||||
* \tparam C Becomes the sequence's new implementation type.
|
||||
*/
|
||||
template <class C> void changeImpl(C = C()) { CSequence c = C(); for (auto i = cbegin(); i != cend(); ++i) c.push_back(*i); *this = std::move(c); }
|
||||
template <class C> void changeImpl(C = C()) { auto c = fromImpl(C()); for (auto i = cbegin(); i != cend(); ++i) c.push_back(*i); *this = std::move(c); }
|
||||
|
||||
/*!
|
||||
* \brief Like changeImpl, but uses the implementation type of another sequence.
|
||||
@@ -508,6 +502,8 @@ namespace BlackMisc
|
||||
typedef QScopedPointer<PimplBase> PimplPtr;
|
||||
PimplPtr m_pimpl;
|
||||
|
||||
explicit CSequence(PimplBase *pimpl) : m_pimpl(pimpl) {} // private ctor used by fromImpl()
|
||||
|
||||
// using these methods to access m_pimpl.data() eases the cognitive burden of correctly forwarding const
|
||||
PimplBase *pimpl() { return m_pimpl.data(); }
|
||||
const PimplBase *pimpl() const { return m_pimpl.data(); }
|
||||
|
||||
Reference in New Issue
Block a user