Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Besides Boost, where can I get a single-file smart pointer implementation for C++?

I want to start using smart pointers in my code but I don't really want to use Boost because it's so huge.

Can anyone recommend a simple, one-file smart pointer implementation?

Thanks, Boda Cydo.

like image 589
bodacydo Avatar asked Feb 03 '26 04:02

bodacydo


2 Answers

Unfortunately, smart pointers are not all that simple, so the implementation may be quite complicated. Having said that, if you are using g++ you get things like shared_ptr without having to use Boost:

#include <memory>
using namespace std;

int main() {
    shared_ptr <int> p( new int );
}

but you will have to compile with the -std=c++0x flag.

You could upgrade to a recent-enough compiler and use what TR1 gives you. The compiler I use has included TR1 pre-releases for many years.

like image 45
Dirk Eddelbuettel Avatar answered Feb 05 '26 20:02

Dirk Eddelbuettel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!