From 768bbb9c3bab499352deca083bf4e7d79c844fe7 Mon Sep 17 00:00:00 2001 From: cxl Date: Fri, 18 Apr 2014 18:44:22 +0000 Subject: [PATCH] Core: WithPick git-svn-id: svn://ultimatepp.org/upp/trunk@7279 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Topt.h | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/uppsrc/Core/Topt.h b/uppsrc/Core/Topt.h index 7c3b0cd43..1e8a2617c 100644 --- a/uppsrc/Core/Topt.h +++ b/uppsrc/Core/Topt.h @@ -267,12 +267,13 @@ public: template class WithDeepCopy : public T { public: - WithDeepCopy(const T& a) : T(a, 1) {} - WithDeepCopy(const WithDeepCopy& a) : T(a, 1) {} - WithDeepCopy& operator=(const WithDeepCopy& a) { (T&)*this <<= a; return *this; } - WithDeepCopy(int, T rval_ a) : T(a) {} - WithDeepCopy& operator^=(T rval_ a) { (T&)*this = pick(a); return *this; } - WithDeepCopy() {} + WithDeepCopy(const T& a) : T(clone(a)) {} + WithDeepCopy(const WithDeepCopy& a) : T(clone(a)){} + WithDeepCopy& operator=(const WithDeepCopy& a) { (T&)*this = clone(a); return *this; } + WithDeepCopy& operator=(const T& a) { (T&)*this = clone(a); return *this; } +// WithDeepCopy(int, T rval_ a) : T(a) {} +// WithDeepCopy& operator^=(T rval_ a) { (T&)*this = pick(a); return *this; } + WithDeepCopy() {} }; template @@ -281,6 +282,21 @@ WithDeepCopy DeepClone(const T& src) return WithDeepCopy(src); } +template +class WithPick : public T { +public: + WithPick(const T& a) : T(pick(a)) {} + WithPick(const WithPick& a) : T(pick(a)) {} + WithPick& operator=(const WithPick& a) { (T&)*this = pick(a); return *this; } + WithPick& operator=(const T& a) { (T&)*this = pick(a); return *this; } +}; + +template +WithPick AsPick(T rval src) +{ + return WithPick(src); +} + // STL compatibility hacks #define STL_ITERATOR_COMPATIBILITY \