Hello,
what is the benefit of this code?
I suggest you should use templates instead. templates
Regards, Guido
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have the following code:
struct SResponse
{
SResponse(bool state, std::any value) : _state(state), _value(value) {}
bool _state = false;
std::any _value;
};
CSomeClass
{
public:
SResponse GetResponse();
};
// implementation
SResponse CSomeClass::GetResponse()
{
std:string message{"Aloha"};
SResponse res(true, std::make_any<std::string>(message);
return res;
}
Using code:
CSomeClass some;
std::any result = some.GetResponse();
std::string message{};
try { message = std::any_cast<std::string>(result.second); }
catch (...) {}
In fact, I have returned std::any. But I want to replace this with something else. But what ? As you can see, in std::any I can put anything, but what can I use instead of std::any ? Because std::any take pretty much memory at 64bit apps. Beside that, std::any is available only from c++17, and this could not be used on old code.
Hello,
what is the benefit of this code?
I suggest you should use templates instead. templates
Regards, Guido