c++ - What would be a correct procedure to deprecate a class template while keeping the class name? -


there's class template deprecate in project.

template<typename t, size_t size> class x {}; 

i've come following scheme that.

stage 1

for next release - let's version "5" - i'm going provide "new" class different name (the replacement) , convert old 1 deprecated alias:

template<size_t elementsize, size_t size> class x2 {};  template<typename t, size_t size> using x __attribute__ ((deprecated)) = x2<sizeof(t), size>; 

this cause warning users of "old" api, code still work.

stage 2

in next version - "6" - i'm going remove "old" deprecated class, rename "new" 1 old name , create deprecated alias:

template<size_t elementsize, size_t size> class x {};  template<size_t elementsize, size_t size> using x2 __attribute__ ((deprecated)) = x<elementsize, size>; 

this again cause warning users.

stage 3

in final step - done in version "7" - i'll remove deprecated alias, leaving changed class.

template<size_t elementsize, size_t size> class x {}; 

this whole scheme has pros (at each stage code compiles , works, warning issued deprecated interface) , cons (the users forced change code twice). did not come better - other options considered involve compilation error @ point. main problem i'm facing here keep name of class (in final stage), change template "signature" <type, value> <value, value>, (as assume) precludes other clever options...

is there better option? if not, above scheme seem "acceptable", or maybe should cause 1 single compilation failure , done that? project in stage of development, i'm not concerned backward compatibility, thought opportunity try out whole process.

an easier solution might introduce pair of macro's.

in phase 1, code defines use_new_api can use new api. in phase 2, code defines use_old_api can still use old api. in phase 3, macro's ignored , code must use new api.

of course, mixing old , new api in 1 program more troublesome, , mixing them in 1 translation unit begging problems.

behind scenes, in phase 1 have #if !(defined(use_old_api) || defined(use_new_api)) #define use_old_api switch on #define use_new_api in phase 2.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -