c++ - "Template typedef" inside a copy constructor doesn't work -


Some backgrounds: I am writing a policy-based Smart Pointer (like SmartPtr in the Loki Library), which can be destructive. Copy carrier such as auto_ptr, therefore, a template copy maker needs to take non-constructor references to modify the object to copy.

What am I trying to do, some people think that the argument taken by the copy constructor is for the policy to defer it when the destructive copying words are not desired here. It has its simplified code, but unfortunately, it does not work because the compiler can not remove template arguments. Any other technique which can be used to achieve the desired behavior?

  template & lt; Typename t, bool isEnabled & gt; Structure AddConst {typedef t type; }; Template & lt; Typename T & gt; Structure AddConst & lt; T, true & gt; {Type-aphed cons t type; }; Struct MyCopyPolicy {static const bool kIsCopyArgConst = true; }; Template & lt; Typename t, class copy policy & gt; Struct "Foo" {// "Template TypePad" to Get Supporting Helpful Tips & lt; Typename T2 & gt; Straight CopyErg {Tiedef TypeName AdConst & lt; Foo & lt; T2, CopyPolicy & gt;, CopyPolicy :: kIsCopyArgConst & gt; :: type type; }; Fu () {} / / template per constructor does not work template & lt; Typename T2 & gt; Fu (typewrite copyiergroup & lt; T2>: type and amp; rhs) {}}; Int main () {Foo & lt; Int, MyCopyPolicy & gt; Foo1; Foo & lt; Double, Mikeopy Policy & gt; Foo2 = foo1; // Error! }   

Maybe something like this can work for you from std :: enable_if to C Using ++ 0x you can simply use Boost easily, or roll your own (this is just a few lines of code).

  #include & lt; Type_traits & gt; Struct MyCopyPolicy {static const bool kIsCopyArgConst = true; }; Template & lt; Typename t, class copy policy & gt; Struct "Foo" {// "Template TypePad" to Get Supporting Helpful Tips & lt; Typename T2 & gt; Struct CopyArg {typedef CopyPolicy type; }; Fu () {} Template & lt; Typename t2 & gt; Foo (Const T2 & RS, Typename Stade :: Enabled_if  copyArg  :: type :: KISKPARG presets; :: type * = 0) {}}; Int main () {Foo & lt; Int, MyCopyPolicy & gt; Foo1; Foo & lt; Double, Mikeopy Policy & gt; Foo2 = foo1; // Fine! }   

I'm not positive it's optimal. It was shot with just one goal, from which one goal is the minimum distance from which you were moving. Maybe this is where you want to go, or maybe you start in the right direction.

Comments