Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning any data type #113

Closed
tomus85 opened this issue Aug 18, 2015 · 0 comments
Closed

Returning any data type #113

tomus85 opened this issue Aug 18, 2015 · 0 comments

Comments

@tomus85
Copy link

tomus85 commented Aug 18, 2015

Morning,

I know this isn't the right place to ask as I don't have an issue with the library. It's more of C++ support. I have looked everywhere on Google and haven't found a solution. I hope you don't mind helping me out, I would very much appreciated it, cheers :-)

I am creating a caching class in C++ so that It can be used in iOS and Android. I have created a simple class, this class is a singleton class:

using json = nlohmann::json;
using namespace std;

class Cache
{
private:
static Cache *instance;
json j;

Cache() {};
Cache(Cache const&)             = delete;
void operator=(Cache const&)    = delete;

public:
static bool fileExists();
static Cache* getInstance();

template<typename T> void add(string key, T t) { j[key] = t; }

// template T get(string key) { return j[key]; }

void persist();

string toString();

};

This is what I have implemented in Objective-C class
cache = Cache::getInstance();

    cache->add("test", "test");
    cache->add("name", true);
    cache->add("again", 199.9);
    NSLog(@"%s", cache->toString().c_str());

So far the result is what I am expecting however I am trying to implement the 'get' method. As you can see I have comment this out in the header file. I would like to implement this method so that whatever key i pass in the parameter I get the value associated with the key. For example

cache->get("test") would return string "test"
cache->get("name") returns bool true
and so on.

What I have commented out requires this syntax 'cache->get<>("key")'.
I would very much appreciate if I could get help implementing the 'get' method.

If this is not the right place to ask as this is not an issue with the framework then I will remove this thread.

Thank you for your time ;-)

@tomus85 tomus85 closed this as completed Aug 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant