Change Value to be non copyable
This commit is contained in:
parent
f5be7c7ba5
commit
4d89a297c5
21
src/value.hh
21
src/value.hh
|
@ -18,23 +18,10 @@ struct Value
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Value(T&& val) : m_value{new Model<T>{std::forward<T>(val)}} {}
|
Value(T&& val) : m_value{new Model<T>{std::forward<T>(val)}} {}
|
||||||
|
|
||||||
Value(const Value& val)
|
Value(const Value& val) = delete;
|
||||||
{
|
|
||||||
if (val.m_value)
|
|
||||||
m_value.reset(val.m_value->clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
Value(Value&&) = default;
|
Value(Value&&) = default;
|
||||||
|
|
||||||
Value& operator=(const Value& val)
|
Value& operator=(const Value& val) = delete;
|
||||||
{
|
|
||||||
if (val.m_value)
|
|
||||||
m_value.reset(val.m_value->clone());
|
|
||||||
else
|
|
||||||
m_value.reset();
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Value& operator=(Value&& val) = default;
|
Value& operator=(Value&& val) = default;
|
||||||
|
|
||||||
explicit operator bool() const { return (bool)m_value; }
|
explicit operator bool() const { return (bool)m_value; }
|
||||||
|
@ -64,17 +51,13 @@ private:
|
||||||
{
|
{
|
||||||
virtual ~Concept() {}
|
virtual ~Concept() {}
|
||||||
virtual const std::type_info& type() const = 0;
|
virtual const std::type_info& type() const = 0;
|
||||||
virtual Concept* clone() const = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Model : public Concept
|
struct Model : public Concept
|
||||||
{
|
{
|
||||||
Model(const T& val) : m_content(val) {}
|
|
||||||
Model(T&& val) : m_content(std::move(val)) {}
|
Model(T&& val) : m_content(std::move(val)) {}
|
||||||
|
|
||||||
const std::type_info& type() const override { return typeid(T); }
|
const std::type_info& type() const override { return typeid(T); }
|
||||||
Concept* clone() const { return new Model(m_content); }
|
|
||||||
|
|
||||||
T m_content;
|
T m_content;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user