Browse Source

SharedResourcePointer: Allow objects with private constructors

develop
Anthony Nicholls 2 years ago
parent
commit
2685604eb3
2 changed files with 13 additions and 1 deletions
  1. +1
    -1
      modules/juce_core/memory/juce_SharedResourcePointer.h
  2. +12
    -0
      modules/juce_core/memory/juce_SharedResourcePointer_test.cpp

+ 1
- 1
modules/juce_core/memory/juce_SharedResourcePointer.h View File

@@ -153,7 +153,7 @@ private:
if (auto locked = ptr.lock()) if (auto locked = ptr.lock())
return locked; return locked;
auto shared = std::make_shared<SharedObjectType>();
const std::shared_ptr<SharedObjectType> shared (new SharedObjectType());
ptr = shared; ptr = shared;
return shared; return shared;
} }


+ 12
- 0
modules/juce_core/memory/juce_SharedResourcePointer_test.cpp View File

@@ -79,6 +79,18 @@ public:
expect (SharedResourcePointer<Object>::getSharedObjectWithoutCreating() == std::nullopt); expect (SharedResourcePointer<Object>::getSharedObjectWithoutCreating() == std::nullopt);
} }
beginTest ("Create objects with private constructors");
{
class ObjectWithPrivateConstructor
{
private:
ObjectWithPrivateConstructor() = default;
friend SharedResourcePointer<ObjectWithPrivateConstructor>;
};
SharedResourcePointer<ObjectWithPrivateConstructor> instance;
}
} }
}; };


Loading…
Cancel
Save