I am working on a project for school and I am essentially creating a doubly linked list using a hybrid of unique_ptrs and raw ptrs.
One of the test cases is reversing the user-defined doubly linked list and return a temporary object. This is fine and I would assume that when the gets returned if I am instantiating another object from it... this would call the move constructor when provided one.
But after testing weirdly enough no constructor at ALL is being called to give you guys an understanding here is the code and ill break it down.
HW08::DList<std::string> list = {"Carlos", "Bob", "Birian", "Hero", "Goat"};
{
HW08::DList<std::string> list2(list.reverse());
list2.print();
}
list.print();
DList reverse() const {
Node<T>* node = tail_;
DList<T> tList(this->size_);
for (int i = 0; i < tList.size(); i++) {
tList[i] = node->val_;
node = node->prev_;
}
return tList;
}
// Constructor with initializer list
DList(std::initializer_list<T> init) : size_(init.size());
// Only size provided constructor
DList(const int &size) : size_(size), tail_(nullptr);
// Copy constructor
DList(const DList &rhs) : size_(rhs.size_);
// Copy assignment
DList &operator=(const DList &rhs);
// Move constructor
DList(DList &&rhs) noexcept : size_(rhs.size_);
// Move assignment
DList &operator=(DList &&rhs);
This is the code essentially I did not provide implementations to the constructors HERE since all that is needed to know is that they are not being called, I am outputting in each of the constructors but none are getting called besides the first object using initializer_list.
init constructor
[ Goat, Hero, Birian, Bob, Carlos ]
Deleter called
Deleter called
Deleter called
Deleter called
Deleter called
[ Carlos, Bob, Birian, Hero, Goat ]
Deleter called
Deleter called
Deleter called
Deleter called
the deleter called is just for debugging purposes in the destructor of the struct I am using to hold val, next, prev