Skip to content

Instantly share code, notes, and snippets.

@shuffle2
Created March 6, 2014 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shuffle2/9380130 to your computer and use it in GitHub Desktop.
Save shuffle2/9380130 to your computer and use it in GitHub Desktop.
dolphin-emu PR #136 test
#include <memory>
#include <cstdio>
#include <cstdint>
//"MakeUnique.h"
#include "make_unique_impl.h"
struct Base {
Base()
: a(0), b(1), c(2) {
}
virtual int x() {
return a + b;
}
int a, b, c;
};
struct NonPod : Base {
virtual int x() {
return b + c;
}
};
int main() {
#ifdef MUNS
#undef MUNS
#endif
#define MUNS ::std
auto a = MUNS::make_unique<uint8_t>(0xaa);
printf("%02x\n", *a);
auto b = MUNS::make_unique<uint8_t[]>(0xbb);
b[10] = 0xbb;
printf("%02x %02x\n", b[0], b[10]);
// should not compile
//auto c = MUNS::make_unique<uint8_t[0xcc]>(operator new(0xcc));
//auto d = MUNS::make_unique<uint8_t[0xdd]>(0xdd);
auto e = MUNS::make_unique<uint32_t *>(new uint32_t);
*e = (uint32_t *)-1;
printf("%p %8x\n", e.get(), *e);
std::unique_ptr<Base> f = MUNS::make_unique<NonPod>();
printf("%8x\n", f->x());
f = MUNS::make_unique<Base>();
printf("%8x\n", f->x());
#ifdef MUNS
#undef MUNS
#endif
#define MUNS ::newstd
a = MUNS::make_unique<uint8_t>(0xaa);
printf("%02x\n", *a);
b = MUNS::make_unique<uint8_t[]>(0xbb);
b[10] = 0xbb;
printf("%02x %02x\n", b[0], b[10]);
// should not compile
//auto c = MUNS::make_unique<uint8_t[0xcc]>(operator new(0xcc));
//auto d = MUNS::make_unique<uint8_t[0xdd]>(0xdd);
e = MUNS::make_unique<uint32_t *>(new uint32_t);
*e = (uint32_t *)-1;
printf("%p %8x\n", e.get(), *e);
f = MUNS::make_unique<NonPod>();
printf("%8x\n", f->x());
f = MUNS::make_unique<Base>();
printf("%8x\n", f->x());
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment