MyTinySTL icon indicating copy to clipboard operation
MyTinySTL copied to clipboard

Achieve a tiny STL in C++11

Results 49 MyTinySTL issues
Sort by recently updated
recently updated
newest added

报了一堆错误,下面贴出了一部分。该如何解决?? `Scanning dependencies of target stltest [ 50%] Building CXX object Test/CMakeFiles/stltest.dir/test.cpp.o In file included from /root/c++/MyTinySTL/Test/list_test.h:8, from /root/c++/MyTinySTL/Test/test.cpp:14: /root/c++/MyTinySTL/Test/../MyTinySTL/list.h: In instantiation of ‘void mystl::list::remove_if(UnaryPredicate) [with UnaryPredicate = bool (*)(int);...

在Vector的插入函数【特指 iterator insert(const_iterator pos, const value_type& value)这一重载】里中的一个判断分支 如果容量大于元素数量,且传入的迭代器不为end_时的代码我觉得可以简化一下 也就是这段: ``` C++ else if (end_ != cap_) { auto new_end = end_; data_allocator::construct(mystl::address_of(*end_), *(end_ - 1)); ++new_end; auto value_copy = value;...

https://github.com/Alinshans/MyTinySTL/blob/62ef9ef4a4f20001a1136ebc01d52d8558f3d6d8/MyTinySTL/basic_string.h#L1743

我看代码里面的RegisterTestCase(TestCase* testcase);函数才是将案例放进容器里,但test.cpp的main函数中没有看到这句话呢,我是错过了哪里,求大佬讲解一下

如题: C++11 拥有 [`forward_list`](https://en.cppreference.com/w/cpp/container/forward_list) 容器。

```cpp ~deque() { if (map_ != nullptr) { clear(); data_allocator::deallocate(*begin_.node, buffer_size); *begin_.node = nullptr; // 内存没有泄漏???clear操作并没有释放内存,应该是写错了 map_allocator::deallocate(map_, map_size_); map_ = nullptr; } } ``` 上述为deque的析构函数,其内部调用了clear函数,但是clear函数内部只调用了`data_allocator::destroy`函数,此函数应该只复制元素析构函数的调用而不释放指针指向的内存。此外`clear`函数内部也调用了`shrink_to_fit()`函数,该函数只是将duque中两头额外的缓冲区内存释放,而内部已使用过的缓冲区并不会释放。析构函数最后只释放了begin_所在缓冲区指针指向的内存空间,这样begin之后的缓冲区(如果存在)将不会被释放,这应该会导致内存泄漏。下面附上相关函数的代码,其中有些注释是我自己写上去的。 ```cpp // 清空 deque 主要操作是将deque中的全部元素析构,并将deque瘦身(删去前后未使用的空间)...

void alloc::deallocate(void *p, size_t n) { // 大于 128 bytes 就调用 free if (n > static_cast(EMaxBytes)) { std::free(p); return; } FreeList *q = static_cast(p); // p小于128,说明他存在我们的内存池中,找到他的链表地址q FreeList *my_free_list; my_free_list =...

mystl::vector vector(10); mystl::vector v(1); *(int*)(v.begin() + 10) = 200; v = vector; std::cout