Skip to content

Commit

Permalink
Reimplement std::make_unique<> for AppleClang
Browse files Browse the repository at this point in the history
  • Loading branch information
UberLambda committed Jun 11, 2021
1 parent 90afb77 commit 0cc6a15
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tests/streamtests/streamtests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <memory>
#include <utility>
#include <vector>
#include <iostream>
#include <fstream>
Expand All @@ -20,13 +21,21 @@ constexpr const char SAMPLE_KTX2[] = "pattern_02_bc2.ktx2";

std::string testImagesPath;

// For AppleClang 12, since it can't find `std::make_unique<>`
template <typename T, typename... Args>
inline std::unique_ptr<T> make_unique(Args&&... args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}


std::unique_ptr<std::streambuf> testImageFilebuf(std::string name)
{
std::string imagePath{testImagesPath};
imagePath += '/';
imagePath += name;

auto filebuf = std::make_unique<std::filebuf>();
auto filebuf = make_unique<std::filebuf>();
filebuf->open(imagePath, std::ios::in);
if (filebuf->is_open())
{
Expand All @@ -46,7 +55,7 @@ class StreambufStream
std::ios::openmode seek_mode = std::ios::in | std::ios::out)
: _streambuf{std::move(streambuf)}
, _seek_mode{seek_mode}
, _stream{std::make_unique<ktxStream>()}
, _stream{make_unique<ktxStream>()}
, _destructed{false}
{
_stream->type = eStreamTypeCustom;
Expand Down Expand Up @@ -254,7 +263,7 @@ TEST_F(ktxStreamTest, CanCreateAutoKtxFromCppStream)
TEST_F(ktxStreamTest, CanWriteKtx1AsKtx2ToCppStream)
{
KTX_error_code err{KTX_INVALID_VALUE};
auto dstStreambuf = std::make_unique<std::stringbuf>();
auto dstStreambuf = make_unique<std::stringbuf>();
StreambufStream dstStream{std::move(dstStreambuf)};

{
Expand Down

0 comments on commit 0cc6a15

Please sign in to comment.