In new C ++ 11 projects, should I delete all operations by default?

I am starting a new project in C ++ 11 and just found out about a key deletethat helps prevent accidental invocation of copy constructors, etc. Is there a “recommended” set of exceptions that I can make around the world to increase type safety, for example, preventing unsigned signatures in expressions? Should I use deleteall 5 operations that I can deletein all my classes by default ?

FYI, this program requires high performance (which is why I use C ++ for the first time in many years), and there are very few times, I want to copy something, so copying is usually an error, although not 100% of the time, therefore I am interested in this particular case, as well as the general case for other programs. I could potentially deletecreate a copy constructor and add a separate method that copies an object in the rare time that I need a copy. Would that be a good idea?

+4
source share
3 answers

Is there a “recommended” set of deletions that I can do globally to increase type safety, for example, preventing unsigned signatures in expressions?

. , , , -.

5 , ?

! -!

, . , (, ), , . , .

, , , , , , . The Old Man C :

, - int. , - ", , , ". , ++. , , . " ". ++. .

:

, , . ?

... ... , . , , , , . , . , , , .

" " , . = default, = delete, , , .

+7

, , .

, unique_ptr. unique_ptr , (, ), , , unique_ptr, .

, unique_ptr :

unique_ptr& operator= (const unique_ptr&) = delete;

, . , . , : " , x- y-?" , x y (, , ) , , , /.

+5

, . delete , .

, delete - boost::noncopyable ++ 11. ++ 11 boost::noncopyable ( ), = delete.

, " ", , (, int to unsigned) . , , C ++ ( ) . , , " " , , " ".

+1

All Articles