From 5e95a4e31d69b9b85941b6211250ade7f61e4e27 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 18 Apr 2015 16:53:39 +0200 Subject: [PATCH] adjust to pass compilation now the solution with the copy policy class is in place, I prefer to return to the more verbose yet clearer notion of distinct constructors for each case on the outer and the inner capsule likewise. The idea with the separate builder class would be significant only if this class would also provide the copy support. This turns out to be difficult, due to the access restrictions and the necessary passing of type parameters. --- src/lib/variant.hpp | 123 +++++++++++++++----------------------------- 1 file changed, 41 insertions(+), 82 deletions(-) diff --git a/src/lib/variant.hpp b/src/lib/variant.hpp index 949cb508f..ed03377b1 100644 --- a/src/lib/variant.hpp +++ b/src/lib/variant.hpp @@ -197,13 +197,13 @@ namespace lib { } virtual void - copyInto (B& target) const override + copyInto (B&) const override { throw error::Logic("Assignment invoked but target is not assignable"); } virtual void - moveInto (B& target) override + moveInto (B&) override { throw error::Logic("Assignment invoked but target is not assignable"); } @@ -215,7 +215,7 @@ namespace lib { : public B { virtual void - copyInto (void* targetStorage) const override + copyInto (void*) const override { throw error::Logic("Copy construction invoked but target allows only move construction"); } @@ -228,13 +228,13 @@ namespace lib { } virtual void - copyInto (B& target) const override + copyInto (B&) const override { throw error::Logic("Assignment invoked but target is not assignable"); } virtual void - moveInto (B& target) override + moveInto (B&) override { throw error::Logic("Assignment invoked but target is not assignable"); } @@ -246,25 +246,25 @@ namespace lib { : public B { virtual void - copyInto (void* targetStorage) const override + copyInto (void*) const override { throw error::Logic("Copy construction invoked but target is noncopyable"); } virtual void - moveInto (void* targetStorage) override + moveInto (void*) override { throw error::Logic("Move construction invoked but target is noncopyable"); } virtual void - copyInto (B& target) const override + copyInto (B&) const override { throw error::Logic("Assignment invoked but target is not assignable"); } virtual void - moveInto (B& target) override + moveInto (B&) override { throw error::Logic("Assignment invoked but target is not assignable"); } @@ -313,8 +313,6 @@ namespace lib { virtual void moveInto (void* targetStorage) =0; virtual void copyInto (Buffer& target) const =0; virtual void moveInto (Buffer& target) =0; -// virtual void operator= (Buffer const&) =0; -// virtual void operator= (Buffer&&) =0; }; @@ -358,41 +356,32 @@ namespace lib { } void - assignValue (TY const& ob) + operator= (Buff const& buff) + { + *this = buff.access(); + } + + void + operator= (Buff&& rref) + { + *this = move (rref.access()); + } + + void + operator= (TY const& ob) { if (&ob != Buffer::ptr()) this->access() = ob; } void - assignValue (TY && rob) + operator= (TY && rob) { this->access() = move(rob); } - - /* == virtual access functions == */ - - virtual void - copyInto (void* targetStorage) const override - { - new(targetStorage) Buff(this->access()); - } - -// virtual void -// operator= (Buffer const& ob) override -// { -// assignValue (downcast(unConst(ob)).access()); -// } -// -// virtual void -// operator= (Buffer&& rref) override -// { -// assignValue (move (downcast(rref).access())); -// } - static Buff& downcast (Buffer& b) { @@ -417,34 +406,6 @@ namespace lib { - template - struct Assign - { - using RawType = typename remove_reference::type; - static_assert (meta::isInList(), - "Type error: the given variant could never hold the required type"); - - - static void - assign (Buffer& buffer, X&& x) - { - buff().assignValue (forward(x)); - } - - - }; - - template - struct Assign::type> - { - - static void - assign (Buffer& buffer, V&& oVar) - { -// oVar.buffer() -// buff().assignValue (forward(oVar)); - } - }; protected: /* === internal interface for managing the storage === */ @@ -481,6 +442,14 @@ namespace lib { new(storage_) Buff (DefaultType()); } + template + Variant(X&& x) + { + using StorageType = typename CanBuildFrom::Type; + + new(storage_) Buff (forward(x)); + } + Variant (Variant& ref) { ref.buffer().copyInto (&storage_); @@ -493,52 +462,42 @@ namespace lib { Variant (Variant&& rref) { - rref.buffer().copyInto (&storage_); - } - - template - Variant(X&& x) - { - using StorageType = typename CanBuildFrom::Type; - - new(storage_) Buff (forward(x)); + rref.buffer().moveInto (&storage_); } template Variant& operator= (X x) { -// using RawType = typename remove_reference::type; -// static_assert (meta::isInList(), -// "Type error: the given variant could never hold the required type"); -// -// buff().assignValue (forward(x)); + using RawType = typename remove_reference::type; + static_assert (meta::isInList(), + "Type error: the given variant could never hold the required type"); - Assign::assign (this->buffer(), forward (x)); + buff() = forward(x); return *this; } -/* + Variant& operator= (Variant& ovar) { - buffer() = ovar.buffer(); + ovar.buffer().copyInto (this->buffer()); return *this; } Variant& operator= (Variant const& ovar) { - buffer() = ovar.buffer(); + ovar.buffer().copyInto (this->buffer()); return *this; } Variant& operator= (Variant&& rvar) { - buffer().operator= (move(rvar.buffer())); + rvar.buffer().moveInto (this->buffer()); return *this; } - */ + #ifdef LIB_TEST_TEST_HELPER_H /* == diagnostic helper == */