WA in BSTOPS and doubt regarding smart pointers

Hi all!

  1. I’ve been trying to solve the problem BST Operations (BSTOPS) (for a year almost XD :man_facepalming:). It passes the sample testcase. Can someone please find me a testcase for which my solution fails? Here’s the code with the necessary explanations in comments. Since this is my first time using smart pointers, can someone also suggest some ways to improve my design?

  2. How do I convert a std::unique_ptr into a std::experimental::observer_ptr in a better way? I’m currently doing it this way.

Thank you! :slight_smile:

1 Like

Dedication :100:

1 Like

Honestly, while it’s great that you’re learning about the bleeding-edge of C++, I’d recommend just ditching observer_ptr - it seems to give a huge decrease in clarity for (very) minimal gains :frowning:

Edit:

To answer the question you asked: no, I don’t see any better way of doing this, given the very restricted set of constructors for std::observer_ptr:

https://en.cppreference.com/w/cpp/experimental/observer_ptr/observer_ptr

1 Like

Thanks for the suggestion! :slight_smile:

I got rid of the mess I’ve made with the std::experimental::observer_ptrs and replaced them with raw pointers here. However, my submission is still fetching me a WA. :frowning:

I’d honestly just skip this Problem, if I were you - see my (gripey!) comments here :slight_smile:

Edit:

A search of the forums reveals plenty of other people being confused by this Problem - it should probably be either repaired or deleted.

2 Likes

Thank you so much for the assistance. :slightly_smiling_face:

1 Like