mardi 28 mars 2017

What is the difference between type, value_type and element_type, and when to use each?

I have written a template class that should expose its template parameter, but I am unsure of the appropriate naming.

I have found three different names for essentially the same thing (as far as I can tell):

  • containers, e.g., std::vector use value_type
  • smart pointers, e.g., std::unique_ptr use element_type
  • std::reference_wrapper uses just type

What is the idea behind these different names? What standard algorithms or trait classes depend on which name? Which name should I use for my class (something in between a smart pointer and reference wrapper)?

Aucun commentaire:

Enregistrer un commentaire