refs #320 Move own implementation of std::make_unique into BlackMisc

This commit is contained in:
Roland Winklmeier
2014-12-25 17:33:34 +01:00
parent 13a05f729e
commit c0265ba0e4
3 changed files with 12 additions and 9 deletions

View File

@@ -6,6 +6,7 @@
#include "voice_vatlib.h" #include "voice_vatlib.h"
#include "voice_channel_vatlib.h" #include "voice_channel_vatlib.h"
#include "blackmisc/logmessage.h" #include "blackmisc/logmessage.h"
#include "blackmisc/blackmiscfreefunctions.h"
#include <QDebug> #include <QDebug>
#include <QTimer> #include <QTimer>
#include <memory> #include <memory>

View File

@@ -17,6 +17,8 @@
#include <QVariant> #include <QVariant>
#include <QDBusArgument> #include <QDBusArgument>
#include <memory>
/*! /*!
* Workaround, to call initResource from namespace. Used in BlackMisc::initResources(). * Workaround, to call initResource from namespace. Used in BlackMisc::initResources().
* Q_INIT_RESOURCE adds resource, here the translation files. * Q_INIT_RESOURCE adds resource, here the translation files.
@@ -162,6 +164,13 @@ namespace BlackMisc
//! Get local host name env.variable //! Get local host name env.variable
const QString &localHostNameEnvVariable(); const QString &localHostNameEnvVariable();
//! Own implementation of std::make_unique, a C++14 feature not provided by GCC in C++11 mode
template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
} // BlackMisc } // BlackMisc
#endif // guard #endif // guard

View File

@@ -4,20 +4,13 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "menus.h" #include "menus.h"
#include "blackmisc/blackmiscfreefunctions.h"
#include <type_traits> #include <type_traits>
#include <cassert> #include <cassert>
#include <string> #include <string>
namespace XBus namespace XBus
{ {
// Own implementation of std::make_unique, a C++14 feature not provided by GCC in C++11 mode
template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
template <typename T> void *voidptr_cast(T i) // "safe" cast from integer to void* template <typename T> void *voidptr_cast(T i) // "safe" cast from integer to void*
{ {
static_assert(std::is_integral<T>::value, "voidptr_cast expects an integer"); static_assert(std::is_integral<T>::value, "voidptr_cast expects an integer");
@@ -77,7 +70,7 @@ namespace XBus
CMenu CMenu::subMenu(std::string name) CMenu CMenu::subMenu(std::string name)
{ {
assert(! name.empty()); assert(! name.empty());
auto items = make_unique<ItemList>(); auto items = BlackMisc::make_unique<ItemList>();
auto itemsVoidPtr = static_cast<void *>(&*items); auto itemsVoidPtr = static_cast<void *>(&*items);
return { XPLMCreateMenu(name.c_str(), m_data->id, XPLMAppendMenuItem(m_data->id, name.c_str(), nullptr, false), handler, itemsVoidPtr), false, std::move(items) }; return { XPLMCreateMenu(name.c_str(), m_data->id, XPLMAppendMenuItem(m_data->id, name.c_str(), nullptr, false), handler, itemsVoidPtr), false, std::move(items) };
} }