Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

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.

fixed bug
Source Link
Incomputable
  • 9.7k
  • 3
  • 34
  • 73
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;
}
deleted 3 characters in body
Source Link
Incomputable
  • 9.7k
  • 3
  • 34
  • 73

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".

added 83 characters in body
Source Link
Incomputable
  • 9.7k
  • 3
  • 34
  • 73
Loading
Source Link
Incomputable
  • 9.7k
  • 3
  • 34
  • 73
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /