4 ms·
Your implementation is missing header guards. It's using placement new wrong in a lot of places (for example, your emplace_back calls the constructor, then the
by Matheus28 5y ago
Your implementation is missing header guards. It's using placement new wrong in a lot of places (for example, your emplace_back calls the constructor, then the assignment operator). It isn't calling destructors on clear. It doesn't have a destructor (to call clear). Probably a couple more issues regarding the initialization/destruction of objects that need to be ironed out.
- deleted 5y ago[deleted]
- _4r6j 5y agoI believe you are talking about *ptr = T(std::forward<Args>(args)...) That's an rvalue ref so std::move is superfluous. Not an assign
- Matheus28 5y agoThis is how it's being done in one of the places: new (ptr) T; // default-initialization of T *ptr = T(std::forward<Args>(args)...); // Constructs a new T, then calls operator=(T&&) on ptr, then destroys the T that got moved I meant he should do the placement new like this: new (ptr) T(std::forward<Args>(args)...) // Constructs directly on ptr See https://godbolt.org/z/9nT94zxoE https://godbolt.org/z/9nT94zxoE
- Matheus28 5y agoAlso, your std::string tests happen to work because it's taking advantage of small string optimization, otherwise it'd leak memory and wouldn't pass valgrind.