c++ - When is a type equal (template specialization)? -
i store configuration type:
using config1 = config<x, y, z>; using config2 = config<a, b, c>; using config3 = config<x, y, z>;
for each config, there's class template specialization, more configuration work:
template <class config> myclass; template <> myclass<config1>{...} template <> myclass<config2>{...} template <> myclass<config3>{...}
now, see, config1
happens have same definition config3
.
the question is:
which specialization taken
config1
,config3
, or: when type equal? it's name or it's actual content?if it's actual content, how can achieve
config1
,config3
invoke different specializations?
config1
, config3
same type, therefore specialization fail with
error: redefinition of 'struct myclass<config<x, y, z> >' struct myclass<config3>{};
you can use inheritance create new type:
using config1 = config<x, y, z>; struct config3 : config1{};
live example: https://ideone.com/4grlaw
Comments
Post a Comment