Background
In C++ unlike other OOP languages, we do not have a Base Class from where All Classes are derived. I understand in MFC and pre STL, some Compilers did had a similar model, so lets leave it out of the discussion and focus on what the standard provides.
In C++11, auto
was introduced to derive the type from rvalue just another way of type deduction of templates. This was a huge relief when one has to write long list of types with all template parameters.
Using Naked Pointers were prone to errors so Smart Pointers were introduced as a remedy for the unavoidable evil.
Use Case
I have a function which should return something that would indicate Null Object when no data was found or if it found needs to return the data. I would like to know, if C++11 has an elegant way of writing the below code, considering, the template types are painful to read.
Code
std::unique_ptr<std::tuple<tstring, int, tstring> > CCOMErrorHandler::PopError()
{
unique_ptr<std::tuple<tstring, int, tstring> > error = nullptr;
if (!m_lstErrors.empty())
{
error = std::unique_ptr<std::tuple<tstring, int, tstring> >(new std::tuple<tstring, int, tstring>(m_lstErrors.front()));
if (error)
{
m_lstErrors.pop_front();
}
}
return(error);
}
One option is to use a typedef
or macro replacement, but generally am not a big FAN as that keeps polluting namespace though you may have to use to few times in your code often only once.
std::optional
serve your purpose nowadays? \$\endgroup\$