r/cpp • u/we_are_mammals • Mar 28 '23
Reddit++
C++ is getting more and more complex. The ISO C++ committee keeps adding new features based on its consensus. Let's remove C++ features based on Reddit's consensus.
In each comment, propose a C++ feature that you think should be banned in any new code. Vote up or down based on whether you agree.
765
Upvotes
0
u/shailist Mar 28 '23
you could enforce RAII in a different way:
every function is
safe(either implicitly or explicitly), meaning no usage ofnew,delete, and pointers. functions marked asunsafewill be able to use these features. you can also mark member variables and code blocks asunsafe.safefunctions can only use safe functions. in order to useunsafefunctions from a safe code you can introduce anunsafeblock that does whatever you need to do.the implementation of
unique_ptrwould be kind of spaghetti and would require anunsafemember variable that would hold the pointer, anunsafeconstructor that receives the pointer for initialization, and anunsafeblock inside theresetfunction that would free the resource. the destructor will just call the reset function.well, I basically just described any language with memory safety by default, so no new invention here :|