-
Notifications
You must be signed in to change notification settings - Fork 543
[CXX-2625] Bring our own make_unique #1028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,43 @@ | ||||||||
#include <algorithm> | ||||||||
#include <cstdint> | ||||||||
#include <new> | ||||||||
|
||||||||
#include <bsoncxx/stdx/make_unique.hpp> | ||||||||
#include <bsoncxx/test_util/catch.hh> | ||||||||
|
||||||||
namespace { | ||||||||
|
||||||||
struct something { | ||||||||
something(int val) : value(val) {} | ||||||||
int value; | ||||||||
}; | ||||||||
|
||||||||
TEST_CASE("Create a unique_ptr") { | ||||||||
auto ptr = bsoncxx::stdx::make_unique<int>(12); | ||||||||
CHECKED_IF(ptr) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Suggest checking Suggestion applies to other There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was going to say that this is desired behavior, but I double-checked the docs and
😐 As someone that has used these macros heavily across dozens projects for several years and seems to have missed this release note, this is an extremely breaking change from Catch2, and there doesn't appear to be a viable alternative?? It seems that I have a lot of tests to go and fix now. I need to go lay down. |
||||||||
CHECK(*ptr == 12); | ||||||||
} | ||||||||
|
||||||||
auto thing = bsoncxx::stdx::make_unique<something>(5); | ||||||||
CHECKED_IF(thing) { | ||||||||
CHECK(thing->value == 5); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
TEST_CASE("Create a unique_ptr<T[]>") { | ||||||||
const unsigned length = 12; | ||||||||
auto ptr = bsoncxx::stdx::make_unique<int[]>(length); | ||||||||
CHECKED_IF(ptr) { | ||||||||
// All elements are direct-initialized, which produces '0' for `int` | ||||||||
CHECK(ptr[0] == 0); | ||||||||
auto res = std::equal_range(ptr.get(), ptr.get() + length, 0); | ||||||||
CHECK(res.first == ptr.get()); | ||||||||
CHECK(res.second == (ptr.get() + length)); | ||||||||
} | ||||||||
|
||||||||
ptr = bsoncxx::stdx::make_unique_for_overwrite<int[]>(length); | ||||||||
std::fill_n(ptr.get(), length, 42); | ||||||||
CHECK(std::all_of(ptr.get(), ptr.get() + length, [](int n) { return n == 42; })); | ||||||||
} | ||||||||
|
||||||||
} // namespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.