C++03 unique_ptr emulation
I've put up a new version of an C++03 emulated unique_ptr here: http://home.roadrunner.com/~hinnant/unique_ptr03.html This is a "boost-ized" emulation (uses boost tools and is in boost namespace), though I have reason to believe it may not work well on VC+ +05 unless the /Za option is used (I've tested only on gcc 4.0). I'm aware of Ion's interprocess version (http://www.boost.org/doc/libs/1_35_0/doc/html/interprocess/interprocess_smar... ), and thank Ion for his support over the years. This new version is not meant to replace Ion's version. It is simply my current best shot at emulating the unique_ptr behavior as specified in the C++0X CD1 draft. Booster's are welcome to take parts of this implementation and use them in places like interprocess/unique_ptr. Or to just use this unique_ptr directly. It consists of only one header: unique_ptr.hpp, and requires only boost headers, not boost cpp files. Basic documentation is included at the link. -Howard
Howard Hinnant wrote:
I've put up a new version of an C++03 emulated unique_ptr here:
http://home.roadrunner.com/~hinnant/unique_ptr03.html
This is a "boost-ized" emulation (uses boost tools and is in boost namespace)
Wouldn't it be useful to make use of the boost C++0x macros to actually use rvalue references when they are available? Not sure whether that would be really useful though.
On Jan 2, 2009, at 8:31 PM, Mathias Gaunard wrote:
Howard Hinnant wrote:
I've put up a new version of an C++03 emulated unique_ptr here: http://home.roadrunner.com/~hinnant/unique_ptr03.html This is a "boost-ized" emulation (uses boost tools and is in boost namespace)
Wouldn't it be useful to make use of the boost C++0x macros to actually use rvalue references when they are available? Not sure whether that would be really useful though.
Perhaps. My focus at the moment was to simply get an emulation going. My hope is that std::unique_ptr will soon follow compiler supported rvalue refs. -Howard
Hi, Howard Hinnant wrote:
I've put up a new version of an C++03 emulated unique_ptr here:
<skip>
I tried to use this implementation with MSVC 7.1 sp1 and 9.0 sp1 and
encounter ICE in the following code:
<code>
#include <cstdlib>
#include <string>
#include "unique_ptr.hpp"
class Base
{
protected:
explicit Base( std::string const & src )
{
target.reset( new char[src.length() + 1] );
memcpy( target.get(), src.c_str(), src.length() );
target[src.length()] = '0';
}
explicit Base( boost::unique_ptr
Would probably specifying the /Zm2000 compiler help?
Can't test it right now. This is the precompiled header memory size, but I
found it to be helpful even in non-precompiled header projects/files.
With Kind Regards,
Ovanes
On Fri, Mar 6, 2009 at 3:30 PM, Sergey Skorokhodov
Hi,
Howard Hinnant wrote:
I've put up a new version of an C++03 emulated unique_ptr here:
<skip>
I tried to use this implementation with MSVC 7.1 sp1 and 9.0 sp1 and encounter ICE in the following code:
<code>
#include <cstdlib> #include <string> #include "unique_ptr.hpp"
class Base { protected: explicit Base( std::string const & src ) { target.reset( new char[src.length() + 1] ); memcpy( target.get(), src.c_str(), src.length() ); target[src.length()] = '0'; }
explicit Base( boost::unique_ptr
src ) : target( move(src) ) {} virtual ~Base() {} private: boost::unique_ptr
target; }; class Derived : public Base { public: explicit Derived( std::string const & src ) : Base( src ) {} explicit Derived( boost::unique_ptr
src ) : Base( move( src ) ) {} virtual ~Derived() {} }; int main(int argc, char * argv[]) { char const TEXT[] = "This is a text"; boost::unique_ptr
ptxt( new char[sizeof(TEXT)] ); Derived drv( move( ptxt ) ); return 0; } </code>
Here is the exact compiler output:
1>c:\prj\vs2005\projects\unique_tsts\unique_tst\unique_tst.cpp(21) : fatal error C1001: An internal error has occurred in the compiler. 1>(compiler file 'f:\dd\vctools\compiler\utc\src\p2\ehexcept.c', line 1454) 1> To work around this problem, try simplifying or changing the program near the locations listed above. 1>Please choose the Technical Support command on the Visual C++ 1> Help menu, or open the Technical Support help file for more information 1>Build log was saved at "file://c:\prj\VS2005\Projects\unique_tsts\unique_tst\Debug\BuildLog.htm" 1>unique_tst - 1 error(s), 0 warning(s)
Is something wrong with my code or is it a "pure" MSVC bug?
TIA
-- Sergey Skorokhodov
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hi,
Howard Hinnant wrote:
I've put up a new version of an C++03 emulated unique_ptr here:
<skip>
I tried to use this implementation with MSVC 7.1 sp1 and 9.0 sp1 and encounter ICE in the following code:
<skip>
Here is the exact compiler output:
1>c:\prj\vs2005\projects\unique_tsts\unique_tst\unique_tst.cpp(21) : fatal error C1001: An internal error has occurred in the compiler.
<skip>
Is something wrong with my code or is it a "pure" MSVC bug?
Ovanes Markarian wrote: Would probably specifying the /Zm2000 compiler help? Can't test it right now. This is the precompiled header memory size, but I found it to be helpful even in non-precompiled header projects/files.
I used /Zm=1000, the compiler got out of heap space with /Zm=2000 :( -- Sergey Skorokhodov
On Mar 6, 2009, at 9:30 AM, Sergey Skorokhodov wrote:
Hi,
Howard Hinnant wrote:
I've put up a new version of an C++03 emulated unique_ptr here:
<skip>
I tried to use this implementation with MSVC 7.1 sp1 and 9.0 sp1 and encounter ICE in the following code:
Sorry I don't have MSVC 7.1 to test against. Fwiw I dropped your code (copy/paste) into g++ 4.0 and it compiled, linked and ran without any memory leak or other memory related problems. -Howard
<code>
#include <cstdlib> #include <string> #include "unique_ptr.hpp"
class Base { protected: explicit Base( std::string const & src ) { target.reset( new char[src.length() + 1] ); memcpy( target.get(), src.c_str(), src.length() ); target[src.length()] = '0'; }
explicit Base( boost::unique_ptr
src ) : target( move(src) ) {} virtual ~Base() {} private: boost::unique_ptr
target; }; class Derived : public Base { public: explicit Derived( std::string const & src ) : Base( src ) {} explicit Derived( boost::unique_ptr
src ) : Base( move( src ) ) {} virtual ~Derived() {} }; int main(int argc, char * argv[]) { char const TEXT[] = "This is a text"; boost::unique_ptr
ptxt( new char[sizeof(TEXT)] ); Derived drv( move( ptxt ) ); return 0; } </code>
Here is the exact compiler output:
1>c:\prj\vs2005\projects\unique_tsts\unique_tst\unique_tst.cpp(21) : fatal error C1001: An internal error has occurred in the compiler. 1>(compiler file 'f:\dd\vctools\compiler\utc\src\p2\ehexcept.c', line 1454) 1> To work around this problem, try simplifying or changing the program near the locations listed above. 1>Please choose the Technical Support command on the Visual C++ 1> Help menu, or open the Technical Support help file for more information 1>Build log was saved at "file://c:\prj\VS2005\Projects\unique_tsts \unique_tst\Debug\BuildLog.htm" 1>unique_tst - 1 error(s), 0 warning(s)
Is something wrong with my code or is it a "pure" MSVC bug?
TIA
-- Sergey Skorokhodov
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hi, Howard Hinnant wrote:
On Mar 6, 2009, at 9:30 AM, Sergey Skorokhodov wrote:
Hi,
Howard Hinnant wrote:
I've put up a new version of an C++03 emulated unique_ptr here:
<skip>
I tried to use this implementation with MSVC 7.1 sp1 and 9.0 sp1 and encounter ICE in the following code:
Sorry I don't have MSVC 7.1 to test against. Fwiw I dropped your code (copy/paste) into g++ 4.0 and it compiled, linked and ran without any memory leak or other memory related problems.
I've tried boost 1.38 with all compilers, available on my system: msvc-7.1, msvc-9.0 and mingw gcc 4.3.3 (source up_tst.cpp). Here is outputs: mingw gcc 4.3.3: compiled successfully msvc-7.1: C:\tst>cl /EHsc /Zm2000 /Iboost_1_38_0 up_tst.cpp Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.6030 for 80x86 Copyright (C) Microsoft Corporation 1984-2002. All rights reserved. up_tst.cpp c:\tst\up_tst.cpp(62) : fatal error C1001: INTERNAL COMPILER ERROR (compiler file 'f:\vs70builds\6030\vc\Compiler\Utc\src\P2\ehexcept.c', line 1348) Please choose the Technical Support command on the Visual C++ Help menu, or open the Technical Support help file for more information msvc-9.0: C:\tst>cl /EHsc /Zm2000 /Iboost_1_38_0 up_tst.cpp Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved. up_tst.cpp c:\tst\up_tst.cpp(62) : fatal error C1001: An internal error has occurred in the compiler. (compiler file 'f:\dd\vctools\compiler\utc\src\p2\ehexcept.c', line 1454) To work around this problem, try simplifying or changing the program near the locations listed above. Please choose the Technical Support command on the Visual C++ Help menu, or open the Technical Support help file for more information So, it really seems to be msvc bug. :( Unfortunately, I don't feel to be qualified enough to think of a workaround. :( <skip> -- Sergey Skorokhodov
Hello boost-users...! I started looking at the boost graph library to use as a "known good implementation" to compare against during tests of my own custom graph. I hadn't thought that what I was doing might be useful for boost, but I then read that it's feasible to build adapters to use alternate vertex/edge stores with the BGL algorithms. So maybe my graph could be applied somewhere?? The code I wrote is for storing dense DAGs in a packed adjacency format. Not rocket science, but it can handle vertex counts in excess of 65,536 on an ordinary 32-bit build using gcc 4 (boost::adjacency matrix seemed to stop working around 12K nodes). Also, the memory is organized so that the connectivity information for higher-numbered vertices always follows that for lowered-numbered vertices... and you can push or pop vertices at the end of the graph, as well as mark vertex IDs as unused. (Neither add_vertex() nor remove_vertex() are implemented in 1.38 for adjacency_matrix) I've released my code under the Boost Software License, and started documenting it in an article here: http://hostilefork.com/nocycle/ You can browse the repository on GitHub if you like. It doesn't have any kind of build system yet... just some source files and a test program: http://github.com/hostilefork/nocycle/tree/master BoostImplementation.hpp was my crack at mirroring the functions of my graph classes in BGL, based on what I could dig up. So I welcome feedback or general better advice of any sort on issues that might catch your attention. (That includes just plain old ideas about "better C++". Do note that there's a lot of public inheritance at the moment, which was intentional to try and keep lines of code down during this early phase. Also, I tried doing some fancy template tricks in things like my Nstate class but got foiled with issues like static member initialization. Template guru insights appreciated!) Just putting it out there for anyone with present or future interest in such things... Regards, Brian
participants (5)
-
Hostile Fork
-
Howard Hinnant
-
Mathias Gaunard
-
Ovanes Markarian
-
Sergey Skorokhodov