请告诉我在这种情况下我是否正确定义了 noexcept 表达式 的条件?
class scheme_host_port
{
public:
using value_type = std::string;
scheme_host_port() = delete;
scheme_host_port(value_type const &value) noexcept(std::is_nothrow_copy_constructible_v<value_type>) : value_{value} {};
scheme_host_port(value_type &&value) noexcept(std::is_nothrow_move_constructible_v<value_type>) : value_{value} {};
scheme_host_port(scheme_host_port const &) = delete;
scheme_host_port &operator=(scheme_host_port const &) = delete;
scheme_host_port(scheme_host_port &&) noexcept(std::is_nothrow_move_constructible_v<value_type>) = default;
scheme_host_port &operator=(scheme_host_port &&) noexcept(std::is_nothrow_move_assignable_v<value_type>) = default;
value_type operator()() const { return value_; }
bool operator==(scheme_host_port const &rhs) const noexcept { return this->value_ == rhs.value_; }
bool operator!=(scheme_host_port const &rhs) const noexcept { return !(this->value_ == rhs.value_); }
private:
value_type value_;
};
class scheme_host_port {
public:
using value_type = std::string;
scheme_host_port() = delete;
// Copy constructor can throw, so no noexcept here
scheme_host_port(value_type const &value) noexcept(false) : value_{value} {}
// Move constructor is noexcept
scheme_host_port(value_type &&value) noexcept : value_{std::move(value)} {}
scheme_host_port(scheme_host_port const &) = delete;
scheme_host_port &operator=(scheme_host_port const &) = delete;
// Default move constructor and move assignment are noexcept
scheme_host_port(scheme_host_port &&) noexcept = default;
scheme_host_port &operator=(scheme_host_port &&) noexcept = default;
value_type operator()() const { return value_; }
// Comparison operators are noexcept
bool operator==(scheme_host_port const &rhs) const noexcept { return this->value_ == rhs.value_; }
bool operator!=(scheme_host_port const &rhs) const noexcept { return !(this->value_ == rhs.value_); }
private:
value_type value_;
};