Add std::make_unique

This commit is contained in:
Vinnie Falco
2014-01-16 18:19:24 -05:00
parent 25ff77c2fd
commit cac1d555be
3 changed files with 97 additions and 11 deletions

View File

@@ -146,6 +146,7 @@
<ClInclude Include="..\..\beast\Intrusive.h" />
<ClInclude Include="..\..\beast\intrusive\List.h" />
<ClInclude Include="..\..\beast\intrusive\LockFreeStack.h" />
<ClInclude Include="..\..\beast\make_unique.h" />
<ClInclude Include="..\..\beast\Memory.h" />
<ClInclude Include="..\..\beast\MPL.h" />
<ClInclude Include="..\..\beast\mpl\IsCallPossible.h" />
@@ -162,7 +163,6 @@
<ClInclude Include="..\..\beast\smart_ptr\SharedPtr.h" />
<ClInclude Include="..\..\beast\StaticAssert.h" />
<ClInclude Include="..\..\beast\STL.h" />
<ClInclude Include="..\..\beast\stl\shared_ptr.h" />
<ClInclude Include="..\..\beast\Strings.h" />
<ClInclude Include="..\..\beast\strings\CharacterFunctions.h" />
<ClInclude Include="..\..\beast\strings\CharPointer_ASCII.h" />
@@ -569,7 +569,6 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\beast\smart_ptr\SmartPtr.cpp" />
<ClCompile Include="..\..\beast\stl\STL.cpp" />
<ClCompile Include="..\..\beast\strings\impl\CharacterFunctions.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>

View File

@@ -279,9 +279,6 @@
<Filter Include="beast\smart_ptr\impl">
<UniqueIdentifier>{df4f2935-13a1-4afe-90cc-d86472ec2466}</UniqueIdentifier>
</Filter>
<Filter Include="beast\stl">
<UniqueIdentifier>{793e2d61-14f6-4fa1-a17f-af6bbec13ba1}</UniqueIdentifier>
</Filter>
<Filter Include="beast\insight">
<UniqueIdentifier>{174b9125-76a7-4796-be97-79c2dcc751f1}</UniqueIdentifier>
</Filter>
@@ -1161,9 +1158,6 @@
<ClInclude Include="..\..\beast\smart_ptr\AbstractObject.h">
<Filter>beast\smart_ptr</Filter>
</ClInclude>
<ClInclude Include="..\..\beast\stl\shared_ptr.h">
<Filter>beast\stl</Filter>
</ClInclude>
<ClInclude Include="..\..\beast\STL.h">
<Filter>beast</Filter>
</ClInclude>
@@ -1245,6 +1239,9 @@
<ClInclude Include="..\..\beast\asio\io_latency_probe.h">
<Filter>beast\asio</Filter>
</ClInclude>
<ClInclude Include="..\..\beast\make_unique.h">
<Filter>beast</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\modules\beast_core\containers\DynamicObject.cpp">
@@ -1775,9 +1772,6 @@
<ClCompile Include="..\..\beast\smart_ptr\impl\AbstractObject.cpp">
<Filter>beast\smart_ptr\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\beast\stl\STL.cpp">
<Filter>beast\stl</Filter>
</ClCompile>
<ClCompile Include="..\..\beast\insight\Insight.cpp">
<Filter>beast\insight</Filter>
</ClCompile>

View File

@@ -0,0 +1,93 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef BEAST_MAKE_UNIQUE_H_INCLUDED
#define BEAST_MAKE_UNIQUE_H_INCLUDED
#include <boost/config.hpp>
namespace std {
#ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES
template <class T>
std::unique_ptr <T> make_unique ()
{
return std::unique_ptr <T> (new T);
}
template <class T, class P1>
std::unique_ptr <T> make_unique (P1&& p1)
{
return std::unique_ptr <T> (new T (std::forward <P1> (p1)));
}
template <class T, class P1, class P2>
std::unique_ptr <T> make_unique (P1&& p1, P2&& p2)
{
return std::unique_ptr <T> (new T (
std::forward <P1> (p1), std::forward <P2> (p2)));
}
template <class T, class P1, class P2, class P3>
std::unique_ptr <T> make_unique (P1&& p1, P2&& p2, P3&& p3)
{
return std::unique_ptr <T> (new T (
std::forward <P1> (p1), std::forward <P2> (p2), std::forward <P3> (p3)));
}
template <class T, class P1, class P2, class P3, class P4>
std::unique_ptr <T> make_unique (P1&& p1, P2&& p2, P3&& p3, P4&& p4)
{
return std::unique_ptr <T> (new T (
std::forward <P1> (p1), std::forward <P2> (p2), std::forward <P3> (p3),
std::forward <P4> (p4)));
}
template <class T, class P1, class P2, class P3, class P4, class P5>
std::unique_ptr <T> make_unique (P1&& p1, P2&& p2, P3&& p3, P4&& p4, P5&& p5)
{
return std::unique_ptr <T> (new T (
std::forward <P1> (p1), std::forward <P2> (p2), std::forward <P3> (p3),
std::forward <P4> (p4), std::forward <P5> (p5)));
}
template <class T, class P1, class P2, class P3, class P4, class P5, class P6>
std::unique_ptr <T> make_unique (P1&& p1, P2&& p2, P3&& p3, P4&& p4, P5&& p5, P6&& p6)
{
return std::unique_ptr <T> (new T (
std::forward <P1> (p1), std::forward <P2> (p2), std::forward <P3> (p3),
std::forward <P4> (p4), std::forward <P5> (p5), std::forward <P6> (p6)));
}
//------------------------------------------------------------------------------
#else
template <class T, class... Args>
std::unique_ptr <T> make_unique (Args&&... args)
{
return std::unique_ptr <T> (new T (std::forward <Args> (args)...));
}
#endif
}
#endif