WIP: Forwarding ctor shadows standard copy operations (#963)

unsuccssful attempt to come up with a generic remedy.
Aborted this attempt and stashed it away as TICKET #963
This commit is contained in:
Fischlurch 2015-07-03 18:08:28 +02:00
parent 8c78af2adc
commit 0cec3490fe
2 changed files with 36 additions and 15 deletions

View file

@ -121,6 +121,33 @@ namespace diff{
using std::string; using std::string;
namespace {//////TODO this is a prototype, to be factored out
template<typename X, class SELF>
struct ShaddowCopyCtor
{
operator bool() const { return true; }
};
template<class SELF>
struct ShaddowCopyCtor<SELF, SELF>
{
// no bool conversion -> substitution fails.
};
template<class SELF>
struct ShaddowCopyCtor<SELF&, SELF>
{
// no bool conversion -> substitution fails.
};
template<class SELF>
struct ShaddowCopyCtor<const SELF, SELF>
{
// no bool conversion -> substitution fails.
};
}//(End) copy shaddowing solution
class GenNode; class GenNode;
using Rec = Record<GenNode>; using Rec = Record<GenNode>;
@ -146,15 +173,11 @@ namespace diff{
{ {
public: public:
template<typename X> template<typename X>
DataCap(X&& x) DataCap(X&& x, bool = ShaddowCopyCtor<X, DataCap>())
: Variant<DataValues>(std::forward<X>(x)) : Variant<DataValues>(std::forward<X>(x))
{ } { }
DataCap(DataCap const& o) =default; ////////////////////////TICKET #963 Forwarding shadows copy operations -- generic solution??
DataCap(DataCap&& o) =default;
DataCap(DataCap& o)
: DataCap((DataCap const&)o)
{ }
}; };
@ -183,8 +206,9 @@ namespace diff{
ID idi; ID idi;
DataCap data; DataCap data;
template<typename X> template<typename X>
GenNode(X&& val) GenNode(X&& val, bool = ShaddowCopyCtor<X, GenNode>())
: idi(&val, buildChildID<X>()) : idi(&val, buildChildID<X>())
, data(std::forward<X>(val)) , data(std::forward<X>(val))
{ } { }
@ -203,12 +227,6 @@ namespace diff{
: GenNode(string(text)) : GenNode(string(text))
{ } { }
GenNode(GenNode const& o) =default;
GenNode(GenNode&& o) =default;
GenNode(GenNode& o)
: GenNode((GenNode const&)o)
{ }
// default copy assignable // default copy assignable

View file

@ -142,12 +142,11 @@ namespace lib {
= meta::InstantiateForEach<typename TYPES::List, ValueAcceptInterface>; = meta::InstantiateForEach<typename TYPES::List, ValueAcceptInterface>;
/////TODO: - is it possible directly to forward the constructor invocation to the object within the buffer? Beware of unverifiable generic solutions!
}//(End) implementation helpers }//(End) implementation helpers
/** /**
* Typesafe union record. * Typesafe union record.
* A Variant element may carry an embedded value of any of the predefined types. * A Variant element may carry an embedded value of any of the predefined types.
@ -160,6 +159,10 @@ namespace lib {
* in question, but type mismatch will provoke an exception at runtime. * in question, but type mismatch will provoke an exception at runtime.
* Generic access is possible using a visitor. * Generic access is possible using a visitor.
* @warning not threadsafe * @warning not threadsafe
* @todo we need to define all copy operations explicitly, due to the
* templated one-arg ctor to wrap the actual values.
* There might be a generic solution for that ////////////////////////TICKET #963 Forwarding shadows copy operations -- generic solution??
* But -- Beware of unverifiable generic solutions!
*/ */
template<typename TYPES> template<typename TYPES>
class Variant class Variant