mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Make SettingChange and StreamCharSourcemove constructors and assignment operators noexcept (#808)
The explicitly defaulted or implemented move constructors and assignment operators are made "noexcept". Bugfix: * src/stream.cpp Stream::Stream() char_traits::int_type intro[4] is now aggregate-initialized (to zero) to avoid UB. Minor changes: * Using std::isinf() and std::signbit() instead of comparing for equality with infinity. * src/streamcharsource.h: Added #include "stream.h". * src/stream.h: Forward declaring "class StreamCharSource". * Some implicit casting changed into static_cast's. Signed-off-by: Ted Lyngmo <ted@lyncon.se>
This commit is contained in:
@@ -7,12 +7,18 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "yaml-cpp/noexcept.h"
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace YAML {
|
||||
class SettingChangeBase;
|
||||
|
||||
class SettingChangeBase {
|
||||
public:
|
||||
virtual ~SettingChangeBase() = default;
|
||||
virtual void pop() = 0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class Setting {
|
||||
@@ -28,12 +34,6 @@ class Setting {
|
||||
T m_value;
|
||||
};
|
||||
|
||||
class SettingChangeBase {
|
||||
public:
|
||||
virtual ~SettingChangeBase() = default;
|
||||
virtual void pop() = 0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class SettingChange : public SettingChangeBase {
|
||||
public:
|
||||
@@ -64,16 +64,25 @@ class SettingChanges {
|
||||
public:
|
||||
SettingChanges() : m_settingChanges{} {}
|
||||
SettingChanges(const SettingChanges&) = delete;
|
||||
SettingChanges(SettingChanges&&) = default;
|
||||
SettingChanges(SettingChanges&&) YAML_CPP_NOEXCEPT = default;
|
||||
SettingChanges& operator=(const SettingChanges&) = delete;
|
||||
SettingChanges& operator=(SettingChanges&& rhs) YAML_CPP_NOEXCEPT {
|
||||
if (this == &rhs)
|
||||
return *this;
|
||||
|
||||
clear();
|
||||
std::swap(m_settingChanges, rhs.m_settingChanges);
|
||||
|
||||
return *this;
|
||||
}
|
||||
~SettingChanges() { clear(); }
|
||||
|
||||
void clear() {
|
||||
void clear() YAML_CPP_NOEXCEPT {
|
||||
restore();
|
||||
m_settingChanges.clear();
|
||||
}
|
||||
|
||||
void restore() {
|
||||
void restore() YAML_CPP_NOEXCEPT {
|
||||
for (setting_changes::const_iterator it = m_settingChanges.begin();
|
||||
it != m_settingChanges.end(); ++it)
|
||||
(*it)->pop();
|
||||
@@ -83,19 +92,8 @@ class SettingChanges {
|
||||
m_settingChanges.push_back(std::move(pSettingChange));
|
||||
}
|
||||
|
||||
// like std::unique_ptr - assignment is transfer of ownership
|
||||
SettingChanges& operator=(SettingChanges&& rhs) {
|
||||
if (this == &rhs)
|
||||
return *this;
|
||||
|
||||
clear();
|
||||
std::swap(m_settingChanges, rhs.m_settingChanges);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
using setting_changes = std::vector<std::unique_ptr<SettingChangeBase> >;
|
||||
using setting_changes = std::vector<std::unique_ptr<SettingChangeBase>>;
|
||||
setting_changes m_settingChanges;
|
||||
};
|
||||
} // namespace YAML
|
||||
|
Reference in New Issue
Block a user