You got very close to strong exception safety. Unfortunately, you've missed one step of the copy and swap idiom. Namely the swap, so even if the deletion throws nothing bad will happen to the data in the container. I recommend this answer this answer to enrich knowledge about C++ exception safety.
You got very close to strong exception safety. Unfortunately, you've missed one step of the copy and swap idiom. Namely the swap, so even if the deletion throws nothing bad will happen to the data in the container. I recommend this answer to enrich knowledge about C++ exception safety.
You got very close to strong exception safety. Unfortunately, you've missed one step of the copy and swap idiom. Namely the swap, so even if the deletion throws nothing bad will happen to the data in the container. I recommend this answer to enrich knowledge about C++ exception safety.
template <typename T>
template <typename ... Args>
void ArrayList<T>::emplace(Args... args)
{
if (allocatedSize == actualSize)
{
//handle buffer resizing
}
new (copy + actualSize) T(args...);
std::swap(copy, arr);
++actualSize;
delete[] copy;
}
template <typename T>
template <typename ... Args>
void ArrayList<T>::emplace(Args... args)
{
if (allocatedSize == actualSize)
{
//handle buffer resizing
}
new (copy + actualSize) T(args...);
std::swap(copy, arr);
delete[] copy;
}
template <typename T>
template <typename ... Args>
void ArrayList<T>::emplace(Args... args)
{
if (allocatedSize == actualSize)
{
//handle buffer resizing
}
new (copy + actualSize) T(args...);
std::swap(copy, arr);
++actualSize;
delete[] copy;
}
C++ has standard std::vector
templated container. It mirrors the concepts of the ArrayList
(contigious buffer, resizing, index based access). On top of that, it uses everything C++ has to offer. I recommend you to think about it this: "When in Rome, do what Romans do".
C++ has standard std::vector
templated container. It mirrors the concepts of the ArrayList
(contigious buffer, resizing, index based access). On top of that, it uses everything C++ has to offer. I recommend you to think about it this: "When in Rome, do what Romans do".
C++ has standard std::vector
templated container. It mirrors the concepts of the ArrayList
(contigious buffer, resizing, index based access). On top of that, it uses everything C++ has to offer. I recommend you to think about this: "When in Rome, do what Romans do".