logoalt Hacker News

schaefertoday at 2:35 PM2 repliesview on HN

in the first example:

```

10: rjk::duck<Container> c{std::vector<int>{1, 2, 3}};

11: c.size(); // 3

12:

13: c = std::string{"hello"};

```

Does the assignment on line 13 call the destrucor for the vector of ints created on line 10?


Replies

RyanJK5today at 2:38 PM

Yes. duck takes ownership of the vector by moving it into its internal storage.

As a bonus, if you tried passing in an lvalue, it will reject the input unless you add the "copyable" trait, so it ends up mitigating some hidden copies.

show 1 reply
rycombtoday at 4:10 PM

Is there another option? Or were you asking if it leaks memory?

Maybe you were asking if it implements custom destructors? GC?

show 1 reply