@@ -349,56 +349,59 @@ struct SexpContextMenuState {
349349 SexpContextMenuState& operator =(const SexpContextMenuState&) = delete ;
350350 SexpContextMenuState (SexpContextMenuState&& other) noexcept
351351 {
352- * this = std::move (other);
352+ swap (other);
353353 }
354354 SexpContextMenuState& operator =(SexpContextMenuState&& other) noexcept
355355 {
356356 if (this != &other) {
357- cleanup ();
358-
359- is_labeled_root = other.is_labeled_root ;
360- is_root_editable = other.is_root_editable ;
361- can_edit_text = other.can_edit_text ;
362- can_edit_comment = other.can_edit_comment ;
363- can_edit_bg_color = other.can_edit_bg_color ;
364- can_add_variable = other.can_add_variable ;
365- can_modify_variable = other.can_modify_variable ;
366- can_copy = other.can_copy ;
367- can_cut = other.can_cut ;
368- can_paste = other.can_paste ;
369- can_paste_add = other.can_paste_add ;
370- can_delete = other.can_delete ;
371- can_replace_number = other.can_replace_number ;
372- can_replace_string = other.can_replace_string ;
373- can_add_number = other.can_add_number ;
374- can_add_string = other.can_add_string ;
375- add_type = other.add_type ;
376- replace_type = other.replace_type ;
377- insert_opf_type = other.insert_opf_type ;
378- add_count = other.add_count ;
379- replace_count = other.replace_count ;
380- modify_variable = other.modify_variable ;
381- campaign_mode = other.campaign_mode ;
382- add_data_list = other.add_data_list ;
383- add_data_opf_type = other.add_data_opf_type ;
384- replace_data_list = other.replace_data_list ;
385- add_enabled_op_indices = std::move (other.add_enabled_op_indices );
386- replace_enabled_op_indices = std::move (other.replace_enabled_op_indices );
387- op_add_enabled = std::move (other.op_add_enabled );
388- op_replace_enabled = std::move (other.op_replace_enabled );
389- op_insert_enabled = std::move (other.op_insert_enabled );
390- replace_variables = std::move (other.replace_variables );
391- show_container_names = other.show_container_names ;
392- replace_container_names = std::move (other.replace_container_names );
393- show_container_data = other.show_container_data ;
394- replace_container_data = std::move (other.replace_container_data );
395-
396- other.add_data_list = nullptr ;
397- other.replace_data_list = nullptr ;
357+ SexpContextMenuState tmp;
358+ swap (other); // take other's resources
359+ other.swap (tmp); // give other a clean state (tmp gets our old resources and destroys them)
398360 }
399361 return *this ;
400362 }
401363
364+ void swap (SexpContextMenuState& other) noexcept
365+ {
366+ using std::swap;
367+ swap (is_labeled_root, other.is_labeled_root );
368+ swap (is_root_editable, other.is_root_editable );
369+ swap (can_edit_text, other.can_edit_text );
370+ swap (can_edit_comment, other.can_edit_comment );
371+ swap (can_edit_bg_color, other.can_edit_bg_color );
372+ swap (can_add_variable, other.can_add_variable );
373+ swap (can_modify_variable, other.can_modify_variable );
374+ swap (can_copy, other.can_copy );
375+ swap (can_cut, other.can_cut );
376+ swap (can_paste, other.can_paste );
377+ swap (can_paste_add, other.can_paste_add );
378+ swap (can_delete, other.can_delete );
379+ swap (can_replace_number, other.can_replace_number );
380+ swap (can_replace_string, other.can_replace_string );
381+ swap (can_add_number, other.can_add_number );
382+ swap (can_add_string, other.can_add_string );
383+ swap (add_type, other.add_type );
384+ swap (replace_type, other.replace_type );
385+ swap (insert_opf_type, other.insert_opf_type );
386+ swap (add_count, other.add_count );
387+ swap (replace_count, other.replace_count );
388+ swap (modify_variable, other.modify_variable );
389+ swap (campaign_mode, other.campaign_mode );
390+ swap (add_data_list, other.add_data_list );
391+ swap (add_data_opf_type, other.add_data_opf_type );
392+ swap (replace_data_list, other.replace_data_list );
393+ swap (add_enabled_op_indices, other.add_enabled_op_indices );
394+ swap (replace_enabled_op_indices, other.replace_enabled_op_indices );
395+ swap (op_add_enabled, other.op_add_enabled );
396+ swap (op_replace_enabled, other.op_replace_enabled );
397+ swap (op_insert_enabled, other.op_insert_enabled );
398+ swap (replace_variables, other.replace_variables );
399+ swap (show_container_names, other.show_container_names );
400+ swap (replace_container_names, other.replace_container_names );
401+ swap (show_container_data, other.show_container_data );
402+ swap (replace_container_data, other.replace_container_data );
403+ }
404+
402405 // Free the dynamically allocated data lists (safe to call multiple times)
403406 void cleanup () {
404407 if (add_data_list) { add_data_list->destroy (); add_data_list = nullptr ; }
0 commit comments