*/
List<T> &operator=(const List<T> &l);
+ /*!
+ * Exchanges the content of this list by the content of \a l.
+ */
+ void swap(List<T> &l);
+
/*!
* Compares this list with \a l and returns true if all of the elements are
* the same.
////////////////////////////////////////////////////////////////////////////////
template <class T>
-List<T>::List()
+List<T>::List() :
+ d(new ListPrivate<T>())
{
- d = new ListPrivate<T>;
}
template <class T>
template <class T>
List<T> &List<T>::operator=(const List<T> &l)
{
- if(&l == this)
- return *this;
-
- if(d->deref())
- delete d;
- d = l.d;
- d->ref();
+ List<T>(l).swap(*this);
return *this;
}
+template <class T>
+void List<T>::swap(List<T> &l)
+{
+ using std::swap;
+
+ swap(d, l.d);
+}
+
template <class T>
bool List<T>::operator==(const List<T> &l) const
{
*/
Map<Key, T> &operator=(const Map<Key, T> &m);
+ /*!
+ * Exchanges the content of this map by the content of \a m.
+ */
+ void swap(Map<Key, T> &m);
+
protected:
/*
* If this List is being shared via implicit sharing, do a deep copy of the
};
template <class Key, class T>
-Map<Key, T>::Map()
+Map<Key, T>::Map() :
+ d(new MapPrivate<Key, T>())
{
- d = new MapPrivate<Key, T>;
}
template <class Key, class T>
template <class Key, class T>
Map<Key, T> &Map<Key, T>::operator=(const Map<Key, T> &m)
{
- if(&m == this)
- return *this;
-
- if(d->deref())
- delete(d);
- d = m.d;
- d->ref();
+ Map<Key, T>(m).swap(*this);
return *this;
}
+template <class Key, class T>
+void Map<Key, T>::swap(Map<Key, T> &m)
+{
+ using std::swap;
+
+ swap(d, m.d);
+}
+
////////////////////////////////////////////////////////////////////////////////
// protected members
////////////////////////////////////////////////////////////////////////////////