mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-17 13:07:54 +02:00
util: introduce helper AnyPtr to access std::any instances
Co-authored-by: Russell Yanofsky <russ@yanofsky.org>
This commit is contained in:
parent
1c7be9ab90
commit
95cccf8a4b
1 changed files with 13 additions and 0 deletions
|
|
@ -25,6 +25,7 @@
|
|||
#include <util/threadnames.h>
|
||||
#include <util/time.h>
|
||||
|
||||
#include <any>
|
||||
#include <exception>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
|
|
@ -500,6 +501,18 @@ inline void insert(std::set<TsetT>& dst, const Tsrc& src) {
|
|||
dst.insert(src.begin(), src.end());
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to access the contained object of a std::any instance.
|
||||
* Returns a pointer to the object if passed instance has a value and the type
|
||||
* matches, nullptr otherwise.
|
||||
*/
|
||||
template<typename T>
|
||||
T* AnyPtr(const std::any& any) noexcept
|
||||
{
|
||||
T* const* ptr = std::any_cast<T*>(&any);
|
||||
return ptr ? *ptr : nullptr;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
class WinCmdLineArgs
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue