🧹 C++17: Use std::make_unique
This commit is contained in:
parent
91f8267db9
commit
4c0581ca5e
3 changed files with 10 additions and 10 deletions
|
|
@ -16,15 +16,15 @@ namespace net {
|
|||
std::unique_ptr<abstract_net> abstract_net::make_net(provider_t provider)
|
||||
{
|
||||
#ifdef NONET
|
||||
return std::unique_ptr<abstract_net>(new loopback);
|
||||
return std::make_unique<loopback>();
|
||||
#else
|
||||
switch (provider) {
|
||||
case SELCONN_TCP:
|
||||
return std::unique_ptr<abstract_net>(new cdwrap<tcp_client>);
|
||||
return std::make_unique<cdwrap<tcp_client>>();
|
||||
case SELCONN_ZT:
|
||||
return std::unique_ptr<abstract_net>(new cdwrap<base_protocol<protocol_zt>>);
|
||||
return std::make_unique<cdwrap<base_protocol<protocol_zt>>>();
|
||||
case SELCONN_LOOPBACK:
|
||||
return std::unique_ptr<abstract_net>(new loopback);
|
||||
return std::make_unique<loopback>();
|
||||
default:
|
||||
ABORT();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -342,19 +342,19 @@ public:
|
|||
|
||||
inline std::unique_ptr<packet> packet_factory::make_packet(buffer_t buf)
|
||||
{
|
||||
std::unique_ptr<packet_in> ret(new packet_in(key));
|
||||
auto ret = std::make_unique<packet_in>(key);
|
||||
ret->create(std::move(buf));
|
||||
ret->decrypt();
|
||||
return std::unique_ptr<packet>(std::move(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <packet_type t, typename... Args>
|
||||
std::unique_ptr<packet> packet_factory::make_packet(Args... args)
|
||||
{
|
||||
std::unique_ptr<packet_out> ret(new packet_out(key));
|
||||
auto ret = std::make_unique<packet_out>(key);
|
||||
ret->create<t>(args...);
|
||||
ret->encrypt();
|
||||
return std::unique_ptr<packet>(std::move(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace net
|
||||
|
|
|
|||
|
|
@ -553,7 +553,7 @@ static bool mpqapi_write_file_contents(const char *pszName, const BYTE *pbData,
|
|||
// We populate the table of sector offset while we write the data.
|
||||
// We can't pre-populate it because we don't know the compressed sector sizes yet.
|
||||
// First offset is the start of the first sector, last offset is the end of the last sector.
|
||||
std::unique_ptr<uint32_t[]> sectoroffsettable(new uint32_t[num_sectors + 1]);
|
||||
auto sectoroffsettable = std::make_unique<uint32_t[]>(num_sectors + 1);
|
||||
|
||||
#ifdef CAN_SEEKP_BEYOND_EOF
|
||||
if (!cur_archive.stream.seekp(pBlk->offset + offset_table_bytesize, std::ios::beg))
|
||||
|
|
@ -566,7 +566,7 @@ static bool mpqapi_write_file_contents(const char *pszName, const BYTE *pbData,
|
|||
const std::uintmax_t cur_size = stream_end - cur_archive.stream_begin;
|
||||
if (cur_size < pBlk->offset + offset_table_bytesize) {
|
||||
if (cur_size < pBlk->offset) {
|
||||
std::unique_ptr<char[]> filler(new char[pBlk->offset - cur_size]);
|
||||
auto filler = std::make_unique<char[]>(pBlk->offset - cur_size);
|
||||
if (!cur_archive.stream.write(filler.get(), pBlk->offset - cur_size))
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue