Project

General

Profile

Necessary Maintenance #8378

Ensure all move constructors and assignment operators are noexcept

Added by Christopher Green about 5 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
Start date:
04/20/2015
Due date:
% Done:

100%

Estimated time:
6.00 h
Spent time:
Scope:
Experiment:
SSI Package:
Duration:

Description

In order to gain the maximum benefit from move semantics with STL containers, all explicitly declared move constructors and assignment operators should be noexcept. Otherwise, the copy operation may be selected instead even when a move might actually be reasonable.

History

#1 Updated by Christopher Green about 5 years ago

  • Target version set to 2.01.00
  • Estimated time set to 6.00 h

We should also make use of the type trait std::is_nothrow_move_constructible where appropriate for the desired level of assurance that any given compiler is doing what we need.

A standalone test in e.g. cetlib might also be reasonable, as there is some uncertainty over whether an explicitly-declared "default" move constructor or operator honors the noexcept status of the explicit declaration or overrides it to be noexcept.

#2 Updated by Christopher Green about 5 years ago

  • Status changed from New to Accepted

#3 Updated by Kyle Knoepfel over 4 years ago

  • % Done changed from 0 to 100

#4 Updated by Kyle Knoepfel over 4 years ago

  • Status changed from Accepted to Resolved
  • Assignee set to Kyle Knoepfel

With the art suite, explicit move constructors/assignment operators are provided for only three classes:

  • cet::value_ptr
  • messagefacility::MaybeLogger_
  • sqlite::stringstream

The noexcept specifier is now included for the appropriate "move" special functions for value_ptr and MaybeLogger_ classes.

For sqlite::stringstream, the single member type is std::deque<std::string>, which is move-assignable but not move-constructible. The sqlite::stringstream move constructor can therefore not be labeled as noexcept. Although an std::vector<std::string> is move-constructible, switching the data type container from an std::deque to an std::vector may result in other inefficiencies due to the frequent popping of the first container element. For that reason, I have kept the std::deque container and added the noexcept specifier to the move assignment operator.

Implemented with commits cetlib:04fb8fc9, messagefacility:9a25aeca, and art:e2a97af9.

#5 Updated by Kyle Knoepfel over 4 years ago

  • Target version changed from 2.01.00 to 1.18.05

#6 Updated by Kyle Knoepfel over 4 years ago

  • Status changed from Resolved to Closed


Also available in: Atom PDF