diff options
| author | ljfa-ag <ljfa-ag@web.de> | 2015-07-07 17:16:25 +0200 |
|---|---|---|
| committer | ljfa-ag <ljfa-ag@web.de> | 2015-07-07 17:16:25 +0200 |
| commit | fd4942b6f56227e9d90ad046ae011bc9db05eae0 (patch) | |
| tree | fd319644ae5d7bb52537270034bb0c3035908dc9 | |
| parent | 49bcfa77e1252fb9e4e55d6a5f97a420f6de8fc4 (diff) | |
| download | Project-Tick-fd4942b6f56227e9d90ad046ae011bc9db05eae0.tar.gz Project-Tick-fd4942b6f56227e9d90ad046ae011bc9db05eae0.zip | |
Make value copyable (after all)
| -rw-r--r-- | include/crtp_tag.h | 4 | ||||
| -rw-r--r-- | include/value.h | 13 | ||||
| -rw-r--r-- | src/value.cpp | 18 |
3 files changed, 20 insertions, 15 deletions
diff --git a/include/crtp_tag.h b/include/crtp_tag.h index 928759d6b8..a871866a2c 100644 --- a/include/crtp_tag.h +++ b/include/crtp_tag.h @@ -55,13 +55,13 @@ namespace detail } //TODO: Add copy constructors for tags that are missing it before this becomes useable - /*template<class Sub> + template<class Sub> std::unique_ptr<tag> crtp_tag<Sub>::clone() const& { return std::unique_ptr<tag>( new Sub(static_cast<const Sub&>(*this)) ); - }*/ + } template<class Sub> std::unique_ptr<tag> crtp_tag<Sub>::move_clone() && diff --git a/include/value.h b/include/value.h index 64e79efe9c..02937c8f5e 100644 --- a/include/value.h +++ b/include/value.h @@ -39,12 +39,14 @@ public: explicit value(std::unique_ptr<tag>&& t); explicit value(tag&& t); - //Movable but not (implicitly) copyable - value(const value&) = delete; + //Moving value(value&&) = default; - value& operator=(const value&) = delete; value& operator=(value&&) = default; + //Copying + explicit value(const value& rhs); + value& operator=(const value& rhs); + /** * @brief Assigns the given value to the tag if the type matches * @throw std::bad_cast if the type of @c t is not the same as the type @@ -128,11 +130,6 @@ public: value& operator[](const std::string& key); value& operator[](const char* key); //need this overload because of conflict with built-in operator[] - /** - * @brief Creates a copy of the value - */ - value copy() const; - std::unique_ptr<tag>& get_ptr(); const std::unique_ptr<tag>& get_ptr() const; void set_ptr(std::unique_ptr<tag>&& t); diff --git a/src/value.cpp b/src/value.cpp index d6c276471a..de173a94c2 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -32,6 +32,19 @@ value::value(tag&& t): tag_(std::move(t).move_clone()) {} +value::value(const value& rhs): + tag_(rhs.tag_ ? rhs.tag_->clone() : nullptr) +{} + +value& value::operator=(const value& rhs) +{ + if(this != &rhs) + { + tag_ = rhs.tag_ ? rhs.tag_->clone() : nullptr; + } + return *this; +} + value& value::operator=(tag&& t) { set(std::move(t)); @@ -356,11 +369,6 @@ value& value::operator[](const char* key) return (*this)[std::string(key)]; } -value value::copy() const -{ - return value(tag_->clone()); -} - std::unique_ptr<tag>& value::get_ptr() { return tag_; |
