Come definire i tipi di ID forti in C++ 11? È possibile fare alias di tipi interi ma ricevere avvisi dal compilatore quando si mescolano i tipi?Come definire i tipi di ID forti in C++ 11?
es:
using monsterID = int;
using weaponID = int;
auto dragon = monsterID{1};
auto sword = weaponID{1};
dragon = sword; // I want a compiler warning here!!
if(dragon == sword){ // also I want a compiler warning here!!
// you should not mix weapons with monsters!!!
}
Non si può fare questo con typedef. Crea nuovi tipi. C'è qualcosa in Boost IIRC. –
http://stackoverflow.com/q/18251447/560648 –
Di interesse è questa nuova funzionalità proposta per C++ 1y: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/ 2013/n3515.pdf –