Remove shared reporter state (+add inplace_any and type_id) #172
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR removes the global state for class-based reporter (see, e.g., console or xml reporters). Before this PR, calling
REGISTER_REPORTER("name", Type);
would create a globalstd::optional<Type>
, which would be assigned whenever the reporter is requested. This works, but means there can only be a single instance of the reporter at any given time. Although this should be OK for 99% of use cases, this is an unnecessary limitation. Theregistry
class should own the reporter instance.The difficulty is we don't know what type the reporter can have, as this is an open ended set (user can add new ones we don't know about). This is normally solved by using polymorphism and
std::unique_ptr<BaseType>
, but we cannot do this as it requires an allocation. Here, this is instead achieved using a type-erased inplace storage,inplace_any
, equivalent ofstd::any
but without any allocation. This storage is used to manage the reporter instance, which is created on demand and destroyed when no longer used.