bodacydo
bodacydo

Reputation: 79499

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.

Upvotes: 3

Views: 248

Answers (4)

Ilia Barahovsky
Ilia Barahovsky

Reputation: 10498

Probably this may help you: http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.22. It's a short example for implementing reference counting. In case you're implementing "shared_ptr" by yourself, cases of simple pointer and array should be distinguished, like in boost.

Upvotes: 0

anon
anon

Reputation:

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.

Upvotes: 4

Loki Astari
Loki Astari

Reputation: 264631

The thing is boost is just a set of header files (the majority).

So when you use things like smart pointers all you get are the smart pointers.
There is no extra cost for the things you are not using.

Upvotes: 1

Dirk is no longer here
Dirk is no longer here

Reputation: 368439

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.

Upvotes: 3

Related Questions