File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -310,4 +310,23 @@ class Incomplete {};
310
310
Incomplete incompleteFunction () { return {}; }
311
311
const Incomplete incompleteFunctionConst () { return {}; }
312
312
313
+ // Check that we can store a pointer-sized payload inline in the unique_function.
314
+ TEST (UniqueFunctionTest, InlineStorageWorks) {
315
+ // We do assume a couple of implementation details of the unique_function here:
316
+ // - It can store certain small-enough payload inline
317
+ // - Inline storage size is at least >= sizeof(void*)
318
+ void *ptr;
319
+ unique_function<void (void *)> UniqueFunctionWithInlineStorage{
320
+ [ptr](void *self) {
321
+ auto mid = reinterpret_cast <uintptr_t >(&ptr);
322
+ auto beg = reinterpret_cast <uintptr_t >(self);
323
+ auto end = reinterpret_cast <uintptr_t >(self) +
324
+ sizeof (unique_function<void (void *)>);
325
+ // Make sure the address of the captured pointer lies somewhere within
326
+ // the unique_function object.
327
+ EXPECT_TRUE (mid >= beg && mid < end);
328
+ }};
329
+ UniqueFunctionWithInlineStorage (&UniqueFunctionWithInlineStorage);
330
+ }
331
+
313
332
} // anonymous namespace
You can’t perform that action at this time.
0 commit comments