refs #108, added CContainerBase::to, for converting between different container types

This commit is contained in:
Mathew Sutcliffe
2014-01-28 20:30:50 +00:00
parent 7c8aa8226d
commit c27da2e38a

View File

@@ -27,6 +27,18 @@ namespace BlackMisc
class CContainerBase : public CValueObject
{
public:
/*!
* \brief Return a new container of a different type, containing the same elements as this one.
* \tparam Other the type of the new container.
* \param other an optional initial value for the new container; will be copied.
*/
template <template <class> class Other>
Other<T> to(Other<T> other = Other<T>()) const
{
for (auto it = derived().cbegin(); it != derived().cend(); ++it) { other.push_back(*it); }
return other;
}
/*!
* \brief Return a copy containing only those elements for which a given predicate returns true.
*/