TITLE: restricting template arguments to only built-in types (part II) (Newsgroups: comp.lang.c++.moderated, 13 Feb 97) ODOWD: "Robert O'Dowd" > > We need a cheap persistent store container, (a map) which only > > takes primitive types. [...] Is there any way to cause a compiler > > error or at least a deliberate run time error if the class is not > > primitive? [ Terminology note: "primitive" == "built-in" -adc ] GLICKSTEIN: Bob Glickstein I can think of an indirect way to do this. It involves the fact that only types with trivial constructors and destructors are allowed in unions. I believe this permits all the types you want (including simple structs and arrays) and excludes all the types you don't. template class CheapPersistentStore { ... private: union only_works_with_primitive_T { T val; }; ... }; You don't need to use the only_works_with_primitive_T union anywhere. Just include it in the template definition, and it should prevent the definition from compiling for any instantiation in which T is non-"primitive".