common::type name - Gemini67/Celma GitHub Wiki

celma::type<>::name()

Provides the name of a type as a printable, well readable string. All type names are available as constexpr.

Examples

  • celma::type< bool>::name() == "bool"
  • celma::type< std::string>::name() == "std::string"
  • celma::type< std::map< int, std::string>>::name() == "std::map<int,std::string>"

Extension for Custom Types

Celma already provides the specialisations for almost all type names from the standard library. If you find a missing overload, or want to add an overload for your custom type, you have to implement a specialisation of the class celma::type.

Example:

namespace celma {
template<> class type<  UserDefinedType>
{
public:
   static constexpr const char* name() { return "UserDefinedType"; }
};
} // namespace celma

Or you use one of the macros that the library uses itself. Just remember to put the code into the namespace celma:

  • PROVIDE_SIMPLE_TYPE_NAME: Macro for non-template classes and enums.
  • PROVIDE_TEMPLATE_TYPE_NAME: Specialisations for templates with exactly one (type) parameter.
  • PROVIDE_KEY_VALUE_TEMPLATE_TYPE_NAME: Specialisations for templates with a key and a value type parameter.

Regarding constexpr

The goal of the type<>::name() functions is, to provide all type names as constexpr. While this already works for simple types, the other expressions for more complex types are not constexpr yet. This is because of a missing feature in g++ 5.4: constexpr static auto member variable initialisation.
The source code is all there, as soon as the feature is available in g++, it can be activated.

⚠️ **GitHub.com Fallback** ⚠️