Skip to content

Instantly share code, notes, and snippets.



Created Sep 1, 2018
What would you like to do?
CRTP inheritance with static fields
#include <iostream>
#include <map>
#include <string>
#include <list>
using namespace std;
// =========== Classe de base: caché a l'utilisateur ==================================
template <typename T>
class Base
void save() {
for (auto & i : metadatas)
cout<<i.first<<" "<<i.second<<" "<<endl;
list<T> all() {};
static map<string, int> metadatas;
#define REGISTER_FIELDS(ClassName,...) template<> map<string, int> Base<ClassName>::metadatas = {__VA_ARGS__};
// L'utilisateur créer des class ====================================================
class User: public Base<User>
REGISTER_FIELDS (User, {"AGE",32},{"TRUC",23})
class Comment: public Base<Comment>
REGISTER_FIELDS (Comment, {"POINT",12},{"NOTE",23})
int main(int argc, char **argv)
User user;;
Comment comm;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.