typestring
typestring copied to clipboard
Maby a nicer Front-Page Example
Thanks for this great class!! (It took me a while to realize that it does exactly what I wanted!)
Please consider putting an example like this on the front-page:
#include "typestring.hh"
// wrapper to give any class T a fixed static name
template <typename T, typename NAME>
class MyClass : public T
{
public:
using T::T;
constexpr static const char *get_name() { return NAME::data(); }
};
#include <vector>
#include <iostream>
int main()
{
MyClass<std::vector<int>, typestring_is("vec0")> vec0{0, 2, 4};
MyClass<std::vector<int>, typestring_is("vec1")> vec1{1, 3, 5};
auto &container = vec0;
std::cout << container.get_name() << std::endl; // prints vec0
}
And consider mentioning typestring
over here
;)