diff --git a/apps/traincascade/old_ml.hpp b/apps/traincascade/old_ml.hpp index 3ad739dd64..75a5d9fffc 100644 --- a/apps/traincascade/old_ml.hpp +++ b/apps/traincascade/old_ml.hpp @@ -2033,7 +2033,8 @@ typedef CvANN_MLP NeuralNet_MLP; typedef CvGBTreesParams GradientBoostingTreeParams; typedef CvGBTrees GradientBoostingTrees; -template<> void DefaultDeleter::operator ()(CvDTreeSplit* obj) const; +template<> struct DefaultDeleter{ void operator ()(CvDTreeSplit* obj) const; }; + } #endif // __cplusplus diff --git a/apps/traincascade/old_ml_tree.cpp b/apps/traincascade/old_ml_tree.cpp index d4826b814f..cfba9ec952 100644 --- a/apps/traincascade/old_ml_tree.cpp +++ b/apps/traincascade/old_ml_tree.cpp @@ -1880,10 +1880,7 @@ double CvDTree::calc_node_dir( CvDTreeNode* node ) namespace cv { -template<> void DefaultDeleter::operator ()(CvDTreeSplit* obj) const -{ - fastFree(obj); -} +void DefaultDeleter::operator ()(CvDTreeSplit* obj) const { fastFree(obj); } DTreeBestSplitFinder::DTreeBestSplitFinder( CvDTree* _tree, CvDTreeNode* _node) { diff --git a/modules/core/include/opencv2/core/core_c.h b/modules/core/include/opencv2/core/core_c.h index e5fe516d26..91513978f1 100644 --- a/modules/core/include/opencv2/core/core_c.h +++ b/modules/core/include/opencv2/core/core_c.h @@ -2805,11 +2805,11 @@ CV_EXPORTS void insertImageCOI(InputArray coiimg, CvArr* arr, int coi=-1); ////// specialized implementations of DefaultDeleter::operator() for classic OpenCV types ////// -template<> CV_EXPORTS void DefaultDeleter::operator ()(CvMat* obj) const; -template<> CV_EXPORTS void DefaultDeleter::operator ()(IplImage* obj) const; -template<> CV_EXPORTS void DefaultDeleter::operator ()(CvMatND* obj) const; -template<> CV_EXPORTS void DefaultDeleter::operator ()(CvSparseMat* obj) const; -template<> CV_EXPORTS void DefaultDeleter::operator ()(CvMemStorage* obj) const; +template<> struct DefaultDeleter{ CV_EXPORTS void operator ()(CvMat* obj) const; }; +template<> struct DefaultDeleter{ CV_EXPORTS void operator ()(IplImage* obj) const; }; +template<> struct DefaultDeleter{ CV_EXPORTS void operator ()(CvMatND* obj) const; }; +template<> struct DefaultDeleter{ CV_EXPORTS void operator ()(CvSparseMat* obj) const; }; +template<> struct DefaultDeleter{ CV_EXPORTS void operator ()(CvMemStorage* obj) const; }; ////////////// convenient wrappers for operating old-style dynamic structures ////////////// diff --git a/modules/core/include/opencv2/core/cvstd_wrapper.hpp b/modules/core/include/opencv2/core/cvstd_wrapper.hpp index 0a30432dbb..e950660694 100644 --- a/modules/core/include/opencv2/core/cvstd_wrapper.hpp +++ b/modules/core/include/opencv2/core/cvstd_wrapper.hpp @@ -27,15 +27,14 @@ Ptr<_Tp> makePtr(const A1&... a1) { return std::make_shared<_Tp>(a1...); } #else // cv::Ptr with compatibility workarounds -template -struct DefaultDeleter +// It should be defined for C-API types only. +// C++ types should use regular "delete" operator. +template struct DefaultDeleter; +#if 0 { -#ifndef _MSC_VER - void operator()(Y* p) const = delete; // not available by default; enabled for specializations only -#else - void operator()(Y* p) const { delete p; } -#endif + void operator()(Y* p) const; }; +#endif namespace sfinae { template @@ -54,7 +53,14 @@ public: }; } // namespace sfinae -template using has_custom_delete = sfinae::has_parenthesis_operator, void, Y*>; +template +struct has_custom_delete + : public std::false_type {}; + +template +struct has_custom_delete, void, T*>::value >::type > + : public std::true_type {}; + template struct Ptr : public std::shared_ptr @@ -78,29 +84,27 @@ struct Ptr : public std::shared_ptr inline Ptr(const std::shared_ptr& o) CV_NOEXCEPT : std::shared_ptr(o) {} inline Ptr(std::shared_ptr&& o) CV_NOEXCEPT : std::shared_ptr(std::move(o)) {} -#ifndef _MSC_VER // Overload with custom DefaultDeleter: Ptr(...) - template::value >::type> - inline Ptr(Y* ptr) : std::shared_ptr(ptr, DefaultDeleter()) {} + template + inline Ptr(const std::true_type&, Y* ptr) : std::shared_ptr(ptr, DefaultDeleter()) {} // Overload without custom deleter: Ptr(...); - template::value, int >::type) > - inline Ptr(Y* ptr) : std::shared_ptr(ptr) {} + template + inline Ptr(const std::false_type&, Y* ptr) : std::shared_ptr(ptr) {} + + template + inline Ptr(Y* ptr) : Ptr(has_custom_delete(), ptr) {} // Overload with custom DefaultDeleter: Ptr(...) - template::value >::type> - inline void reset(Y* ptr) { std::shared_ptr::reset(ptr, DefaultDeleter()); } + template + inline void reset(const std::true_type&, Y* ptr) { std::shared_ptr::reset(ptr, DefaultDeleter()); } // Overload without custom deleter: Ptr(...); - template::value, int >::type) > - inline void reset(Y* ptr) { std::shared_ptr::reset(ptr); } -#else template - inline Ptr(Y* ptr) : std::shared_ptr(ptr, DefaultDeleter()) {} + inline void reset(const std::false_type&, Y* ptr) { std::shared_ptr::reset(ptr); } template - inline void reset(Y* ptr) { std::shared_ptr::reset(ptr, DefaultDeleter()); } -#endif + inline void reset(Y* ptr) { Ptr::reset(has_custom_delete(), ptr); } template void reset(Y* ptr, Deleter d) { std::shared_ptr::reset(ptr, d); } @@ -131,12 +135,8 @@ struct Ptr : public std::shared_ptr template static inline Ptr<_Tp> makePtr(const A1&... a1) { -#ifndef _MSC_VER static_assert( !has_custom_delete<_Tp>::value, "Can't use this makePtr with custom DefaultDeleter"); return (Ptr<_Tp>)std::make_shared<_Tp>(a1...); -#else - return Ptr<_Tp>(new _Tp(a1...), DefaultDeleter<_Tp>()); -#endif } #endif // CV_DOXYGEN diff --git a/modules/core/include/opencv2/core/persistence.hpp b/modules/core/include/opencv2/core/persistence.hpp index 790dde83f6..22e611ea36 100644 --- a/modules/core/include/opencv2/core/persistence.hpp +++ b/modules/core/include/opencv2/core/persistence.hpp @@ -475,7 +475,7 @@ public: int state; //!< the writer state }; -template<> CV_EXPORTS void DefaultDeleter::operator ()(CvFileStorage* obj) const; +template<> struct DefaultDeleter{ CV_EXPORTS void operator ()(CvFileStorage* obj) const; }; /** @brief File Storage Node class. diff --git a/modules/core/src/array.cpp b/modules/core/src/array.cpp index 49b533b8e9..7c85ed9f71 100644 --- a/modules/core/src/array.cpp +++ b/modules/core/src/array.cpp @@ -3205,23 +3205,12 @@ cvCheckTermCriteria( CvTermCriteria criteria, double default_eps, namespace cv { -template<> void DefaultDeleter::operator ()(CvMat* obj) const -{ cvReleaseMat(&obj); } - -template<> void DefaultDeleter::operator ()(IplImage* obj) const -{ cvReleaseImage(&obj); } - -template<> void DefaultDeleter::operator ()(CvMatND* obj) const -{ cvReleaseMatND(&obj); } - -template<> void DefaultDeleter::operator ()(CvSparseMat* obj) const -{ cvReleaseSparseMat(&obj); } - -template<> void DefaultDeleter::operator ()(CvMemStorage* obj) const -{ cvReleaseMemStorage(&obj); } - -template<> void DefaultDeleter::operator ()(CvFileStorage* obj) const -{ cvReleaseFileStorage(&obj); } +void DefaultDeleter::operator ()(CvMat* obj) const { cvReleaseMat(&obj); } +void DefaultDeleter::operator ()(IplImage* obj) const { cvReleaseImage(&obj); } +void DefaultDeleter::operator ()(CvMatND* obj) const { cvReleaseMatND(&obj); } +void DefaultDeleter::operator ()(CvSparseMat* obj) const { cvReleaseSparseMat(&obj); } +void DefaultDeleter::operator ()(CvMemStorage* obj) const { cvReleaseMemStorage(&obj); } +void DefaultDeleter::operator ()(CvFileStorage* obj) const { cvReleaseFileStorage(&obj); } template static inline void scalarToRawData_(const Scalar& s, T * const buf, const int cn, const int unroll_to) diff --git a/modules/core/test/test_ptr.cpp b/modules/core/test/test_ptr.cpp index 24d947c36d..87fd559283 100644 --- a/modules/core/test/test_ptr.cpp +++ b/modules/core/test/test_ptr.cpp @@ -382,15 +382,14 @@ struct SpeciallyDeletable bool deleted; }; -} +} // namespace namespace cv { - -template<> -void DefaultDeleter::operator()(SpeciallyDeletable * obj) const -{ obj->deleted = true; } - -} +template<> struct DefaultDeleter +{ + void operator()(SpeciallyDeletable * obj) const { obj->deleted = true; } +}; +} // namespace namespace opencv_test { namespace { diff --git a/modules/objdetect/include/opencv2/objdetect.hpp b/modules/objdetect/include/opencv2/objdetect.hpp index 21eef2341f..f0396d976b 100644 --- a/modules/objdetect/include/opencv2/objdetect.hpp +++ b/modules/objdetect/include/opencv2/objdetect.hpp @@ -163,7 +163,7 @@ CV_EXPORTS void groupRectangles_meanshift(std::vector& rectList, std::ve std::vector& foundScales, double detectThreshold = 0.0, Size winDetSize = Size(64, 128)); -template<> CV_EXPORTS void DefaultDeleter::operator ()(CvHaarClassifierCascade* obj) const; +template<> struct DefaultDeleter{ CV_EXPORTS void operator ()(CvHaarClassifierCascade* obj) const; }; enum { CASCADE_DO_CANNY_PRUNING = 1, CASCADE_SCALE_IMAGE = 2, diff --git a/modules/objdetect/src/cascadedetect.cpp b/modules/objdetect/src/cascadedetect.cpp index d39d47d5e7..f506341de3 100644 --- a/modules/objdetect/src/cascadedetect.cpp +++ b/modules/objdetect/src/cascadedetect.cpp @@ -1603,8 +1603,7 @@ bool CascadeClassifierImpl::read_(const FileNode& root) return featureEvaluator->read(fn, data.origWinSize); } -template<> void DefaultDeleter::operator ()(CvHaarClassifierCascade* obj) const -{ cvReleaseHaarClassifierCascade(&obj); } +void DefaultDeleter::operator ()(CvHaarClassifierCascade* obj) const { cvReleaseHaarClassifierCascade(&obj); } BaseCascadeClassifier::~BaseCascadeClassifier() diff --git a/modules/photo/src/inpaint.cpp b/modules/photo/src/inpaint.cpp index adab6a3c9e..b5472c56d6 100644 --- a/modules/photo/src/inpaint.cpp +++ b/modules/photo/src/inpaint.cpp @@ -724,10 +724,7 @@ icvNSInpaintFMM(const CvMat *f, CvMat *t, CvMat *out, int range, CvPriorityQueue } namespace cv { -template<> void cv::DefaultDeleter::operator ()(IplConvKernel* obj) const -{ - cvReleaseStructuringElement(&obj); -} +template<> struct DefaultDeleter{ void operator ()(IplConvKernel* obj) const { cvReleaseStructuringElement(&obj); } }; } void diff --git a/modules/videoio/include/opencv2/videoio.hpp b/modules/videoio/include/opencv2/videoio.hpp index bb4e3986c8..968dd1fdbe 100644 --- a/modules/videoio/include/opencv2/videoio.hpp +++ b/modules/videoio/include/opencv2/videoio.hpp @@ -954,8 +954,8 @@ protected: Size frameSize, bool isColor = true); }; -template<> CV_EXPORTS void DefaultDeleter::operator ()(CvCapture* obj) const; -template<> CV_EXPORTS void DefaultDeleter::operator ()(CvVideoWriter* obj) const; +template<> struct DefaultDeleter{ CV_EXPORTS void operator ()(CvCapture* obj) const; }; +template<> struct DefaultDeleter{ CV_EXPORTS void operator ()(CvVideoWriter* obj) const; }; //! @} videoio diff --git a/modules/videoio/src/cap.cpp b/modules/videoio/src/cap.cpp index 9c14be018f..b7cf851efa 100644 --- a/modules/videoio/src/cap.cpp +++ b/modules/videoio/src/cap.cpp @@ -45,12 +45,8 @@ namespace cv { -template<> void DefaultDeleter::operator ()(CvCapture* obj) const -{ cvReleaseCapture(&obj); } - -template<> void DefaultDeleter::operator ()(CvVideoWriter* obj) const -{ cvReleaseVideoWriter(&obj); } - +void DefaultDeleter::operator ()(CvCapture* obj) const { cvReleaseCapture(&obj); } +void DefaultDeleter::operator ()(CvVideoWriter* obj) const { cvReleaseVideoWriter(&obj); } VideoCapture::VideoCapture()