mirror of https://github.com/PCSX2/pcsx2.git
common: add make_unique for C++11
v2: fix windows compilation v3: fix copyright date
This commit is contained in:
parent
6be52e435d
commit
756176118b
|
@ -123,6 +123,7 @@
|
|||
<ClInclude Include="..\..\include\Utilities\General.h" />
|
||||
<ClInclude Include="..\..\include\Utilities\HashMap.h" />
|
||||
<ClInclude Include="..\..\include\Utilities\MathUtils.h" />
|
||||
<ClInclude Include="..\..\include\Utilities\MakeUnique.h" />
|
||||
<ClInclude Include="..\..\include\Utilities\MemcpyFast.h" />
|
||||
<ClInclude Include="..\..\include\Utilities\Path.h" />
|
||||
<ClInclude Include="..\..\src\Utilities\PrecompiledHeader.h" />
|
||||
|
|
|
@ -162,6 +162,9 @@
|
|||
<ClInclude Include="..\..\include\Utilities\MathUtils.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\Utilities\MakeUnique.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\Utilities\MemcpyFast.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
|
|
@ -224,6 +224,7 @@ public:
|
|||
#include <list>
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include "MakeUnique.h" // make_unique for C++11
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
/* PCSX2 - PS2 Emulator for PCs
|
||||
* Copyright (C) 2017-2017 PCSX2 Dev Team
|
||||
*
|
||||
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU Lesser General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with PCSX2.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
// make_unique is quite handy but it requires to enable C++14 support (of
|
||||
// course on C++14 compliant compiler)
|
||||
//
|
||||
// Instead just provide the std++ implementation when only C++11 is enabled
|
||||
// File could be dropped when we switch to C++14
|
||||
|
||||
#if __cplusplus <= 201103L && !defined(_MSC_VER)
|
||||
|
||||
namespace std
|
||||
{
|
||||
|
||||
template <typename _Tp>
|
||||
struct _MakeUniq
|
||||
{
|
||||
typedef std::unique_ptr<_Tp> __single_object;
|
||||
};
|
||||
|
||||
template <typename _Tp>
|
||||
struct _MakeUniq<_Tp[]>
|
||||
{
|
||||
typedef std::unique_ptr<_Tp[]> __array;
|
||||
};
|
||||
|
||||
template <typename _Tp, size_t _Bound>
|
||||
struct _MakeUniq<_Tp[_Bound]>
|
||||
{
|
||||
struct __invalid_type
|
||||
{
|
||||
};
|
||||
};
|
||||
|
||||
/// std::make_unique for single objects
|
||||
template <typename _Tp, typename... _Args>
|
||||
inline typename _MakeUniq<_Tp>::__single_object
|
||||
make_unique(_Args &&... __args)
|
||||
{
|
||||
return std::unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...));
|
||||
}
|
||||
|
||||
/// std::make_unique for arrays of unknown bound
|
||||
template <typename _Tp>
|
||||
inline typename _MakeUniq<_Tp>::__array
|
||||
make_unique(size_t __num)
|
||||
{
|
||||
return std::unique_ptr<_Tp>(new typename remove_extent<_Tp>::type[__num]());
|
||||
}
|
||||
|
||||
/// Disable std::make_unique for arrays of known bound
|
||||
template <typename _Tp, typename... _Args>
|
||||
inline typename _MakeUniq<_Tp>::__invalid_type
|
||||
make_unique(_Args &&...) = delete;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -58,6 +58,7 @@ set(UtilitiesHeaders
|
|||
../../include/Utilities/FixedPointTypes.h
|
||||
../../include/Utilities/General.h
|
||||
../../include/Utilities/HashMap.h
|
||||
../../include/Utilities/MakeUnique.h
|
||||
../../include/Utilities/MemcpyFast.h
|
||||
../../include/Utilities/MemsetFast.inl
|
||||
../../include/Utilities/Path.h
|
||||
|
|
Loading…
Reference in New Issue