I'm writing a json library that has the same usage as nlohmann/json. But I'm having trouble understanding nlohmann's get() function. So I implemented a get() myself, but I think that my method is not very good, do you have any good solutions or suggest?
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;
bool func(bool) { return 1; }
int func(int) { return 2; }
double func(double) { return 3; }
string func(string&) { return string("4"); }
vector<int> func(vector<int>&) { return { 5 }; }
map<int, int> func(map<int, int>&) {
map<int, int>a;
a.emplace(6, 6);
return a;
}
template <typename T>
T get() {
static T t;
return func(t);
}
int main() {
cout << get<bool>();
cout << get<int>();
cout << get<double>();
cout << get<string>();
cout << get<vector<int>>()[0];
cout << get<map<int, int>>()[6];
}