[c++0x] unique_ptr.hpp implementation
Chris Fairles
chris.fairles@gmail.com
Sun Aug 12 19:36:00 GMT 2007
Attached is an implementation of unique_ptr (according to
N2315=07-0175) along with a test suite (albiet, incomplete). This
implementation is largely based on:
http://home.twcny.rr.com/hinnant/cpp_extensions/unique_ptr.html
Noteable differences are:
- uses c++0x type traits (enable_if, conditional etc)
- EBO without the use of boost's compreessed_ptr
- disable reset in array specializations for convertible pointer types
- use pointer-to-private-member for unspecified bool/pointer types
Issues:
- should you be able to use function pointers as a deleter? i.e.
void d(int *p){delete p;}
int* p = new int;
unique_ptr<int, void(*)(int*)> ptr(p, &d);
- can't use member function ptrs in a similar manner since you have to
use .* or ->* to call member function and that requires an object
which you don't have
I'd appreciate some feedback, like how well it fits the standard since
this is my first attempt at implementing straight out of a c++ std.
Any design issues or subtle flaws as well.
Cheers,
Chris
P.S. I'm using latest gcc svn head to compile/test this (rev. 127375).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: unique_ptr_test.cpp
Type: text/x-c++src
Size: 20346 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20070812/821bd681/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: unique_ptr.hpp
Type: text/x-c++hdr
Size: 19462 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20070812/821bd681/attachment-0001.bin>
More information about the Libstdc++
mailing list