@@ -7,9 +7,10 @@ Wrapper: A template wrapper around EDProducts to hold the product ID.
77
88----------------------------------------------------------------------*/
99
10+ #include " DataFormats/Common/interface/Uninitialized.h"
11+ #include " DataFormats/Common/interface/CMS_CLASS_VERSION.h"
1012#include " DataFormats/Common/interface/WrapperBase.h"
1113#include " DataFormats/Common/interface/WrapperDetail.h"
12- #include " DataFormats/Common/interface/CMS_CLASS_VERSION.h"
1314#include " DataFormats/Provenance/interface/ProductID.h"
1415#include " FWCore/Utilities/interface/Visibility.h"
1516
@@ -25,7 +26,7 @@ namespace edm {
2526 public:
2627 typedef T value_type;
2728 typedef T wrapped_type; // used with the dictionary to identify Wrappers
28- Wrapper () : WrapperBase(), obj() , present(false ) {}
29+ Wrapper () : WrapperBase(), obj{ construct_ ()} , present(false ) {}
2930 explicit Wrapper (std::unique_ptr<T> ptr);
3031 Wrapper (Wrapper<T> const & rh) = delete ; // disallow copy construction
3132 Wrapper<T>& operator =(Wrapper<T> const &) = delete ; // disallow assignment
@@ -49,6 +50,14 @@ namespace edm {
4950 CMS_CLASS_VERSION (4 )
5051
5152 private:
53+ constexpr T construct_ () {
54+ if constexpr (requires { T (); }) {
55+ return T ();
56+ } else {
57+ return T (edm::kUninitialized );
58+ }
59+ }
60+
5261 bool isPresent_ () const override { return present; }
5362 std::type_info const & dynamicTypeInfo_ () const override { return typeid (T); }
5463 std::type_info const & wrappedTypeInfo_ () const override { return typeid (Wrapper<T>); }
@@ -78,7 +87,7 @@ namespace edm {
7887 };
7988
8089 template <typename T>
81- Wrapper<T>::Wrapper(std::unique_ptr<T> ptr) : WrapperBase(), obj() , present(ptr.get() != nullptr ) {
90+ Wrapper<T>::Wrapper(std::unique_ptr<T> ptr) : WrapperBase(), obj{ construct_ ()} , present(ptr.get() != nullptr ) {
8291 if (present) {
8392 obj = std::move (*ptr);
8493 }
@@ -89,7 +98,7 @@ namespace edm {
8998 Wrapper<T>::Wrapper(Emplace, Args&&... args) : WrapperBase(), obj(std::forward<Args>(args)...), present(true ) {}
9099
91100 template <typename T>
92- Wrapper<T>::Wrapper(T* ptr) : WrapperBase(), present(ptr != 0 ), obj() {
101+ Wrapper<T>::Wrapper(T* ptr) : WrapperBase(), present(ptr != 0 ), obj{ construct_ ()} {
93102 std::unique_ptr<T> temp (ptr);
94103 if (present) {
95104 obj = std::move (*ptr);
0 commit comments