From e64857c5611d5898b7b30640a775331488a5ebef Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Fri, 19 Jan 2024 08:53:08 -0500 Subject: [PATCH] Merge pull request #23736 from seanm:c++11-simplifications Removed all pre-C++11 code, workarounds, and branches #23736 This removes a bunch of pre-C++11 workrarounds that are no longer necessary as C++11 is now required. It is a nice clean up and simplification. * No longer unconditionally #include in cvdef.h, include explicitly where needed * Removed deprecated CV_NODISCARD, already unused in the codebase * Removed some pre-C++11 workarounds, and simplified some backwards compat defines * Removed CV_CXX_STD_ARRAY * Removed CV_CXX_MOVE_SEMANTICS and CV_CXX_MOVE * Removed all tests of CV_CXX11, now assume it's always true. This allowed removing a lot of dead code. * Updated some documentation consequently. * Removed all tests of CV_CXX11, now assume it's always true * Fixed links. --------- Co-authored-by: Maksim Shabunin Co-authored-by: Alexander Smorkalov --- .../how_to_use_OpenCV_parallel_for_.markdown | 19 ++-- modules/core/include/opencv2/core/async.hpp | 4 - modules/core/include/opencv2/core/cvdef.h | 88 ++++--------------- .../opencv2/core/detail/async_promise.hpp | 2 - .../opencv2/core/detail/exception_ptr.hpp | 8 +- modules/core/include/opencv2/core/eigen.hpp | 3 +- modules/core/include/opencv2/core/mat.hpp | 1 + modules/core/include/opencv2/core/matx.hpp | 4 - .../core/utils/allocator_stats.impl.hpp | 56 +----------- modules/core/src/async.cpp | 33 ------- modules/core/src/matrix_wrap.cpp | 10 --- modules/core/src/parallel.cpp | 3 +- modules/core/src/system.cpp | 39 +------- modules/core/test/test_async.cpp | 4 +- modules/core/test/test_misc.cpp | 4 - modules/core/test/test_precomp.hpp | 2 + modules/core/test/test_utils_tls.impl.hpp | 6 -- modules/dnn/src/net_impl.cpp | 4 - modules/dnn/src/net_impl.hpp | 2 - modules/dnn/src/onnx/onnx_importer.cpp | 1 + modules/dnn/test/test_misc.cpp | 4 - modules/imgcodecs/src/loadsave.cpp | 7 -- modules/objdetect/src/precomp.hpp | 2 + modules/objdetect/src/qrcode.cpp | 1 + modules/objdetect/test/test_precomp.hpp | 6 +- modules/objdetect/test/test_qrcode_encode.cpp | 10 --- modules/python/src2/cv2_util.cpp | 4 - modules/python/src2/hdr_parser.py | 3 +- modules/stitching/src/precomp.hpp | 1 + modules/ts/include/opencv2/ts.hpp | 4 - modules/videoio/src/cap_mfx_common.hpp | 15 ---- modules/videoio/src/cap_msmf.cpp | 1 + .../how_to_use_OpenCV_parallel_for_.cpp | 12 ++- .../how_to_use_OpenCV_parallel_for_new.cpp | 12 ++- .../mat_the_basic_image_container.cpp | 4 +- samples/dnn/object_detection.cpp | 2 +- 36 files changed, 65 insertions(+), 316 deletions(-) diff --git a/doc/tutorials/core/how_to_use_OpenCV_parallel_for_/how_to_use_OpenCV_parallel_for_.markdown b/doc/tutorials/core/how_to_use_OpenCV_parallel_for_/how_to_use_OpenCV_parallel_for_.markdown index 4c68efecd0..ab24d27ab1 100644 --- a/doc/tutorials/core/how_to_use_OpenCV_parallel_for_/how_to_use_OpenCV_parallel_for_.markdown +++ b/doc/tutorials/core/how_to_use_OpenCV_parallel_for_/how_to_use_OpenCV_parallel_for_.markdown @@ -9,6 +9,9 @@ How to use the OpenCV parallel_for_ to parallelize your code {#tutorial_how_to_u | -: | :- | | Compatibility | OpenCV >= 3.0 | + +@note See also C++ lambda usage with parallel for in [tuturial](@ref tutorial_how_to_use_OpenCV_parallel_for_new). + Goal ---- @@ -20,7 +23,7 @@ If you want more information about multithreading, you will have to refer to a r to remain simple. Precondition ----- +------------ The first precondition is to have OpenCV built with a parallel framework. In OpenCV 3.2, the following parallel frameworks are available in that order: @@ -50,7 +53,7 @@ We will use the example of drawing a Mandelbrot set to show how from a regular s the code to parallelize the computation. Theory ------------ +------ The Mandelbrot set definition has been named in tribute to the mathematician Benoit Mandelbrot by the mathematician Adrien Douady. It has been famous outside of the mathematics field as the image representation is an example of a @@ -69,7 +72,7 @@ Here, we will just introduce the formula to draw the Mandelbrot set (from the me > \f[\limsup_{n\to\infty}|z_{n+1}|\leqslant2\f] Pseudocode ------------ +---------- A simple algorithm to generate a representation of the Mandelbrot set is called the ["escape time algorithm"](https://en.wikipedia.org/wiki/Mandelbrot_set#Escape_time_algorithm). @@ -110,10 +113,10 @@ On this figure, we recall that the real part of a complex number is on the x-axi You can see that the whole shape can be repeatedly visible if we zoom at particular locations. Implementation ------------ +-------------- Escape time algorithm implementation --------------------------- +------------------------------------ @snippet how_to_use_OpenCV_parallel_for_.cpp mandelbrot-escape-time-algorithm @@ -121,7 +124,7 @@ Here, we used the [`std::complex`](http://en.cppreference.com/w/cpp/numeric/comp complex number. This function performs the test to check if the pixel is in set or not and returns the "escaped" iteration. Sequential Mandelbrot implementation --------------------------- +------------------------------------ @snippet how_to_use_OpenCV_parallel_for_.cpp mandelbrot-sequential @@ -149,7 +152,7 @@ The green curve corresponds to a simple linear scale transformation, the blue on and you can observe how the lowest values will be boosted when looking at the slope at these positions. Parallel Mandelbrot implementation --------------------------- +---------------------------------- When looking at the sequential implementation, we can notice that each pixel is computed independently. To optimize the computation, we can perform multiple pixel calculations in parallel, by exploiting the multi-core architecture of modern @@ -181,7 +184,7 @@ C++ 11 standard allows to simplify the parallel implementation by get rid of the @snippet how_to_use_OpenCV_parallel_for_.cpp mandelbrot-parallel-call-cxx11 Results ------------ +------- You can find the full tutorial code [here](https://github.com/opencv/opencv/blob/4.x/samples/cpp/tutorial_code/core/how_to_use_OpenCV_parallel_for_/how_to_use_OpenCV_parallel_for_.cpp). The performance of the parallel implementation depends of the type of CPU you have. For instance, on 4 cores / 8 threads diff --git a/modules/core/include/opencv2/core/async.hpp b/modules/core/include/opencv2/core/async.hpp index 54560c7d00..98868a130b 100644 --- a/modules/core/include/opencv2/core/async.hpp +++ b/modules/core/include/opencv2/core/async.hpp @@ -7,10 +7,8 @@ #include -#ifdef CV_CXX11 //#include #include -#endif namespace cv { @@ -69,7 +67,6 @@ public: CV_WRAP bool valid() const CV_NOEXCEPT; -#ifdef CV_CXX11 inline AsyncArray(AsyncArray&& o) { p = o.p; o.p = NULL; } inline AsyncArray& operator=(AsyncArray&& o) CV_NOEXCEPT { std::swap(p, o.p); return *this; } @@ -89,7 +86,6 @@ public: std::future getFutureMat() const; std::future getFutureUMat() const; #endif -#endif // PImpl diff --git a/modules/core/include/opencv2/core/cvdef.h b/modules/core/include/opencv2/core/cvdef.h index b55ac3b4ba..b6879ff5a5 100644 --- a/modules/core/include/opencv2/core/cvdef.h +++ b/modules/core/include/opencv2/core/cvdef.h @@ -753,88 +753,43 @@ __CV_ENUM_FLAGS_BITWISE_XOR_EQ (EnumType, EnumType) /****************************************************************************************\ -* CV_NODISCARD attribute (deprecated, GCC only) * -* DONT USE: use instead the standard CV_NODISCARD_STD macro above * -* this legacy method silently fails to issue warning until some version * -* after gcc 6.3.0. Yet with gcc 7+ you can use the above standard method * -* which makes this method useless. Don't use it. * -* @deprecated use instead CV_NODISCARD_STD * +* C++ 11 * \****************************************************************************************/ -#ifndef CV_NODISCARD -# if defined(__GNUC__) -# define CV_NODISCARD __attribute__((__warn_unused_result__)) -# elif defined(__clang__) && defined(__has_attribute) -# if __has_attribute(__warn_unused_result__) -# define CV_NODISCARD __attribute__((__warn_unused_result__)) +#ifdef __cplusplus +// MSVC was stuck at __cplusplus == 199711L for a long time, even where it supports C++11, +// so check _MSC_VER instead. See: +// +# if defined(_MSC_VER) +# if _MSC_VER < 1800 +# error "OpenCV 4.x+ requires enabled C++11 support" # endif +# elif __cplusplus < 201103L +# error "OpenCV 4.x+ requires enabled C++11 support" # endif #endif -#ifndef CV_NODISCARD -# define CV_NODISCARD /* nothing by default */ -#endif - -/****************************************************************************************\ -* C++ 11 * -\****************************************************************************************/ #ifndef CV_CXX11 -# if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800) -# define CV_CXX11 1 -# endif -#else -# if CV_CXX11 == 0 -# undef CV_CXX11 -# endif -#endif -#ifndef CV_CXX11 -# error "OpenCV 4.x+ requires enabled C++11 support" +# define CV_CXX11 1 #endif -#define CV_CXX_MOVE_SEMANTICS 1 -#define CV_CXX_MOVE(x) std::move(x) -#define CV_CXX_STD_ARRAY 1 -#include #ifndef CV_OVERRIDE # define CV_OVERRIDE override #endif + #ifndef CV_FINAL # define CV_FINAL final #endif #ifndef CV_NOEXCEPT -# if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS 2015*/) -# define CV_NOEXCEPT noexcept -# endif -#endif -#ifndef CV_NOEXCEPT -# define CV_NOEXCEPT +# define CV_NOEXCEPT noexcept #endif #ifndef CV_CONSTEXPR -# if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS 2015*/) -# define CV_CONSTEXPR constexpr -# endif -#endif -#ifndef CV_CONSTEXPR -# define CV_CONSTEXPR +# define CV_CONSTEXPR constexpr #endif // Integer types portability -#ifdef OPENCV_STDINT_HEADER -#include OPENCV_STDINT_HEADER -#elif defined(__cplusplus) -#if defined(_MSC_VER) && _MSC_VER < 1600 /* MSVS 2010 */ -namespace cv { -typedef signed char int8_t; -typedef unsigned char uint8_t; -typedef signed short int16_t; -typedef unsigned short uint16_t; -typedef signed int int32_t; -typedef unsigned int uint32_t; -typedef signed __int64 int64_t; -typedef unsigned __int64 uint64_t; -} -#elif defined(_MSC_VER) || __cplusplus >= 201103L +#ifdef __cplusplus #include namespace cv { using std::int8_t; @@ -846,19 +801,6 @@ using std::uint32_t; using std::int64_t; using std::uint64_t; } -#else -#include -namespace cv { -typedef ::int8_t int8_t; -typedef ::uint8_t uint8_t; -typedef ::int16_t int16_t; -typedef ::uint16_t uint16_t; -typedef ::int32_t int32_t; -typedef ::uint32_t uint32_t; -typedef ::int64_t int64_t; -typedef ::uint64_t uint64_t; -} -#endif #else // pure C #include #endif diff --git a/modules/core/include/opencv2/core/detail/async_promise.hpp b/modules/core/include/opencv2/core/detail/async_promise.hpp index 6eb3fb52c1..c039ec046a 100644 --- a/modules/core/include/opencv2/core/detail/async_promise.hpp +++ b/modules/core/include/opencv2/core/detail/async_promise.hpp @@ -52,10 +52,8 @@ public: */ void setException(const cv::Exception& exception); -#ifdef CV_CXX11 explicit AsyncPromise(AsyncPromise&& o) { p = o.p; o.p = NULL; } AsyncPromise& operator=(AsyncPromise&& o) CV_NOEXCEPT { std::swap(p, o.p); return *this; } -#endif // PImpl diff --git a/modules/core/include/opencv2/core/detail/exception_ptr.hpp b/modules/core/include/opencv2/core/detail/exception_ptr.hpp index d98ffc40c6..a1a591e455 100644 --- a/modules/core/include/opencv2/core/detail/exception_ptr.hpp +++ b/modules/core/include/opencv2/core/detail/exception_ptr.hpp @@ -8,14 +8,8 @@ #ifndef CV__EXCEPTION_PTR # if defined(__ANDROID__) && defined(ATOMIC_INT_LOCK_FREE) && ATOMIC_INT_LOCK_FREE < 2 # define CV__EXCEPTION_PTR 0 // Not supported, details: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58938 -# elif defined(CV_CXX11) +# else # define CV__EXCEPTION_PTR 1 -# elif defined(_MSC_VER) -# define CV__EXCEPTION_PTR (_MSC_VER >= 1600) -# elif defined(__clang__) -# define CV__EXCEPTION_PTR 0 // C++11 only (see above) -# elif defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__) -# define CV__EXCEPTION_PTR (__GXX_EXPERIMENTAL_CXX0X__ > 0) # endif #endif #ifndef CV__EXCEPTION_PTR diff --git a/modules/core/include/opencv2/core/eigen.hpp b/modules/core/include/opencv2/core/eigen.hpp index f176409cc3..231c6805c0 100644 --- a/modules/core/include/opencv2/core/eigen.hpp +++ b/modules/core/include/opencv2/core/eigen.hpp @@ -61,8 +61,7 @@ #endif #if !defined(OPENCV_DISABLE_EIGEN_TENSOR_SUPPORT) -#if EIGEN_WORLD_VERSION == 3 && EIGEN_MAJOR_VERSION >= 3 \ - && defined(CV_CXX11) && defined(CV_CXX_STD_ARRAY) +#if EIGEN_WORLD_VERSION == 3 && EIGEN_MAJOR_VERSION >= 3 #include #define OPENCV_EIGEN_TENSOR_SUPPORT 1 #endif // EIGEN_WORLD_VERSION == 3 && EIGEN_MAJOR_VERSION >= 3 diff --git a/modules/core/include/opencv2/core/mat.hpp b/modules/core/include/opencv2/core/mat.hpp index c4c6ff6d78..2bfb0966c2 100644 --- a/modules/core/include/opencv2/core/mat.hpp +++ b/modules/core/include/opencv2/core/mat.hpp @@ -53,6 +53,7 @@ #include "opencv2/core/bufferpool.hpp" +#include #include namespace cv diff --git a/modules/core/include/opencv2/core/matx.hpp b/modules/core/include/opencv2/core/matx.hpp index c5e769f0ab..b4b2e7ef17 100644 --- a/modules/core/include/opencv2/core/matx.hpp +++ b/modules/core/include/opencv2/core/matx.hpp @@ -376,10 +376,8 @@ public: static Vec randn(_Tp a, _Tp b); static Vec randu(_Tp a, _Tp b); static Vec zeros(); -#ifdef CV_CXX11 static Vec diag(_Tp alpha) = delete; static Vec eye() = delete; -#endif //! per-element multiplication Vec mul(const Vec<_Tp, cn>& v) const; @@ -402,9 +400,7 @@ public: const _Tp& operator ()(int i) const; _Tp& operator ()(int i); -#ifdef CV_CXX11 Vec<_Tp, cn>& operator=(const Vec<_Tp, cn>& rhs) = default; -#endif Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_AddOp); Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_SubOp); diff --git a/modules/core/include/opencv2/core/utils/allocator_stats.impl.hpp b/modules/core/include/opencv2/core/utils/allocator_stats.impl.hpp index eb5ecde16b..bbc6cf8979 100644 --- a/modules/core/include/opencv2/core/utils/allocator_stats.impl.hpp +++ b/modules/core/include/opencv2/core/utils/allocator_stats.impl.hpp @@ -9,8 +9,6 @@ //#define OPENCV_DISABLE_ALLOCATOR_STATS -#ifdef CV_CXX11 - #include #ifndef OPENCV_ALLOCATOR_STATS_COUNTER_TYPE @@ -26,14 +24,6 @@ #define OPENCV_ALLOCATOR_STATS_COUNTER_TYPE long long #endif -#else // CV_CXX11 - -#ifndef OPENCV_ALLOCATOR_STATS_COUNTER_TYPE -#define OPENCV_ALLOCATOR_STATS_COUNTER_TYPE int // CV_XADD supports int only -#endif - -#endif // CV_CXX11 - namespace cv { namespace utils { #ifdef CV__ALLOCATOR_STATS_LOG @@ -59,7 +49,7 @@ public: void onAllocate(size_t /*sz*/) {} void onFree(size_t /*sz*/) {} -#elif defined(CV_CXX11) +#else protected: typedef OPENCV_ALLOCATOR_STATS_COUNTER_TYPE counter_t; @@ -104,49 +94,7 @@ public: #endif curr -= (counter_t)sz; } - -#else // non C++11 - -protected: - typedef OPENCV_ALLOCATOR_STATS_COUNTER_TYPE counter_t; - volatile counter_t curr, total, total_allocs, peak; // overflow is possible, CV_XADD operates with 'int' only -public: - AllocatorStatistics() - : curr(0), total(0), total_allocs(0), peak(0) - {} - ~AllocatorStatistics() CV_OVERRIDE {} - - uint64_t getCurrentUsage() const CV_OVERRIDE { return (uint64_t)curr; } - uint64_t getTotalUsage() const CV_OVERRIDE { return (uint64_t)total; } - uint64_t getNumberOfAllocations() const CV_OVERRIDE { return (uint64_t)total_allocs; } - uint64_t getPeakUsage() const CV_OVERRIDE { return (uint64_t)peak; } - - void resetPeakUsage() CV_OVERRIDE { peak = curr; } - - // Controller interface - void onAllocate(size_t sz) - { -#ifdef CV__ALLOCATOR_STATS_LOG - CV__ALLOCATOR_STATS_LOG(cv::format("allocate: %lld (curr=%lld)", (long long int)sz, (long long int)curr)); -#endif - - counter_t new_curr = (counter_t)CV_XADD(&curr, (counter_t)sz) + (counter_t)sz; - - peak = std::max((counter_t)peak, new_curr); // non-thread safe - - //CV_XADD(&total, (uint64_t)sz); // overflow with int, non-reliable... - total += sz; - - CV_XADD(&total_allocs, (counter_t)1); - } - void onFree(size_t sz) - { -#ifdef CV__ALLOCATOR_STATS_LOG - CV__ALLOCATOR_STATS_LOG(cv::format("free: %lld (curr=%lld)", (long long int)sz, (long long int)curr)); -#endif - CV_XADD(&curr, (counter_t)-sz); - } -#endif +#endif // OPENCV_DISABLE_ALLOCATOR_STATS }; #ifdef CV__ALLOCATOR_STATS_LOG diff --git a/modules/core/src/async.cpp b/modules/core/src/async.cpp index 78c0a1ee81..3aeaaf7394 100644 --- a/modules/core/src/async.cpp +++ b/modules/core/src/async.cpp @@ -3,7 +3,6 @@ // of this distribution and at http://opencv.org/license.html. #include "precomp.hpp" -//#undef CV_CXX11 // debug non C++11 mode #include "opencv2/core/async.hpp" #include "opencv2/core/detail/async_promise.hpp" @@ -16,11 +15,9 @@ #ifndef OPENCV_DISABLE_THREAD_SUPPORT -#ifdef CV_CXX11 #include #include #include -#endif namespace cv { @@ -37,12 +34,8 @@ struct AsyncArray::Impl void releasePromise() CV_NOEXCEPT { CV_XADD(&refcount_promise, -1); if(1 == CV_XADD(&refcount, -1)) delete this; } \ int refcount_promise; -#ifdef CV_CXX11 mutable std::mutex mtx; mutable std::condition_variable cond_var; -#else - mutable cv::Mutex mtx; -#endif mutable bool has_result; // Mat, UMat or exception @@ -88,11 +81,7 @@ struct AsyncArray::Impl if (!wait_for(timeoutNs)) return false; } -#ifdef CV_CXX11 std::unique_lock lock(mtx); -#else - cv::AutoLock lock(mtx); -#endif if (has_result) { if (!result_mat.empty()) @@ -145,7 +134,6 @@ struct AsyncArray::Impl if (timeoutNs == 0) return has_result; CV_LOG_INFO(NULL, "Waiting for async result ..."); -#ifdef CV_CXX11 std::unique_lock lock(mtx); const auto cond_pred = [&]{ return has_result == true; }; if (timeoutNs > 0) @@ -156,9 +144,6 @@ struct AsyncArray::Impl CV_Assert(has_result); return true; } -#else - CV_Error(Error::StsNotImplemented, "OpenCV has been built without async waiting support (C++11 is required)"); -#endif } AsyncArray getArrayResult() @@ -175,11 +160,7 @@ struct AsyncArray::Impl { if (future_is_returned && refcount_future == 0) CV_Error(Error::StsError, "Associated AsyncArray has been destroyed"); -#ifdef CV_CXX11 std::unique_lock lock(mtx); -#else - cv::AutoLock lock(mtx); -#endif CV_Assert(!has_result); int k = value.kind(); if (k == _InputArray::UMAT) @@ -193,9 +174,7 @@ struct AsyncArray::Impl value.copyTo(*result_mat.get()); } has_result = true; -#ifdef CV_CXX11 cond_var.notify_all(); -#endif } #if CV__EXCEPTION_PTR @@ -203,18 +182,12 @@ struct AsyncArray::Impl { if (future_is_returned && refcount_future == 0) CV_Error(Error::StsError, "Associated AsyncArray has been destroyed"); -#ifdef CV_CXX11 std::unique_lock lock(mtx); -#else - cv::AutoLock lock(mtx); -#endif CV_Assert(!has_result); has_exception = true; exception = e; has_result = true; -#ifdef CV_CXX11 cond_var.notify_all(); -#endif } #endif @@ -222,18 +195,12 @@ struct AsyncArray::Impl { if (future_is_returned && refcount_future == 0) CV_Error(Error::StsError, "Associated AsyncArray has been destroyed"); -#ifdef CV_CXX11 std::unique_lock lock(mtx); -#else - cv::AutoLock lock(mtx); -#endif CV_Assert(!has_result); has_exception = true; cv_exception = e; has_result = true; -#ifdef CV_CXX11 cond_var.notify_all(); -#endif } }; diff --git a/modules/core/src/matrix_wrap.cpp b/modules/core/src/matrix_wrap.cpp index bb61ce2de1..fa9a23ee2a 100644 --- a/modules/core/src/matrix_wrap.cpp +++ b/modules/core/src/matrix_wrap.cpp @@ -1919,12 +1919,7 @@ void _OutputArray::move(UMat& u) const int k = kind(); if (k == UMAT) { -#ifdef CV_CXX11 *(UMat*)obj = std::move(u); -#else - *(UMat*)obj = u; - u.release(); -#endif } else if (k == MAT) { @@ -1959,12 +1954,7 @@ void _OutputArray::move(Mat& m) const } else if (k == MAT) { -#ifdef CV_CXX11 *(Mat*)obj = std::move(m); -#else - *(Mat*)obj = m; - m.release(); -#endif } else if (k == MATX) { diff --git a/modules/core/src/parallel.cpp b/modules/core/src/parallel.cpp index 4525928b94..84e94da877 100644 --- a/modules/core/src/parallel.cpp +++ b/modules/core/src/parallel.cpp @@ -912,8 +912,7 @@ int getNumberOfCPUs_() * the minimum most value as it has high probablity of being right and safe. * Return 1 if we get 0 or not found on all methods. */ -#if defined CV_CXX11 \ - && !defined(__MINGW32__) /* not implemented (2020-03) */ \ +#if !defined(__MINGW32__) /* not implemented (2020-03) */ /* * Check for this standard C++11 way, we do not return directly because diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index 0a6e2f5037..b9d3ecaa1a 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -305,9 +305,7 @@ DECLARE_CV_CPUID_X86 #endif #endif -#if defined CV_CXX11 - #include -#endif +#include namespace cv { @@ -909,50 +907,15 @@ bool useOptimized(void) int64 getTickCount(void) { -#if defined CV_CXX11 std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); return (int64)now.time_since_epoch().count(); -#elif defined _WIN32 || defined WINCE - LARGE_INTEGER counter; - QueryPerformanceCounter( &counter ); - return (int64)counter.QuadPart; -#elif defined __MACH__ && defined __APPLE__ - return (int64)mach_absolute_time(); -#elif defined __unix__ - struct timespec tp; - clock_gettime(CLOCK_MONOTONIC, &tp); - return (int64)tp.tv_sec*1000000000 + tp.tv_nsec; -#else - struct timeval tv; - gettimeofday(&tv, NULL); - return (int64)tv.tv_sec*1000000 + tv.tv_usec; -#endif } double getTickFrequency(void) { -#if defined CV_CXX11 using clock_period_t = std::chrono::steady_clock::duration::period; double clock_freq = clock_period_t::den / clock_period_t::num; return clock_freq; -#elif defined _WIN32 || defined WINCE - LARGE_INTEGER freq; - QueryPerformanceFrequency(&freq); - return (double)freq.QuadPart; -#elif defined __MACH__ && defined __APPLE__ - static double freq = 0; - if( freq == 0 ) - { - mach_timebase_info_data_t sTimebaseInfo; - mach_timebase_info(&sTimebaseInfo); - freq = sTimebaseInfo.denom*1e9/sTimebaseInfo.numer; - } - return freq; -#elif defined __unix__ - return 1e9; -#else - return 1e6; -#endif } #if defined __GNUC__ && (defined __i386__ || defined __x86_64__ || defined __ppc__) diff --git a/modules/core/test/test_async.cpp b/modules/core/test/test_async.cpp index 58bcfddcd7..2fcee300cf 100644 --- a/modules/core/test/test_async.cpp +++ b/modules/core/test/test_async.cpp @@ -7,7 +7,7 @@ #include -#if defined(CV_CXX11) && !defined(OPENCV_DISABLE_THREAD_SUPPORT) +#if !defined(OPENCV_DISABLE_THREAD_SUPPORT) #include #include #endif @@ -85,7 +85,7 @@ TEST(Core_Async, LikePythonTest) } -#if defined(CV_CXX11) && !defined(OPENCV_DISABLE_THREAD_SUPPORT) +#if !defined(OPENCV_DISABLE_THREAD_SUPPORT) TEST(Core_Async, AsyncThread_Simple) { diff --git a/modules/core/test/test_misc.cpp b/modules/core/test/test_misc.cpp index 6f50600f40..39d0788d64 100644 --- a/modules/core/test/test_misc.cpp +++ b/modules/core/test/test_misc.cpp @@ -8,10 +8,8 @@ #include -#ifdef CV_CXX11 #include #include -#endif namespace opencv_test { namespace { @@ -282,9 +280,7 @@ public: // FP state is not supported // no checks } -#ifdef CV_CXX11 std::this_thread::sleep_for(std::chrono::milliseconds(100)); -#endif } cv::details::FPDenormalsModeState base_state; diff --git a/modules/core/test/test_precomp.hpp b/modules/core/test/test_precomp.hpp index 81ddf45de9..3d9e5a9f39 100644 --- a/modules/core/test/test_precomp.hpp +++ b/modules/core/test/test_precomp.hpp @@ -4,6 +4,8 @@ #ifndef __OPENCV_TEST_PRECOMP_HPP__ #define __OPENCV_TEST_PRECOMP_HPP__ +#include + #include "opencv2/ts.hpp" #include "opencv2/ts/ocl_test.hpp" #include "opencv2/core/private.hpp" diff --git a/modules/core/test/test_utils_tls.impl.hpp b/modules/core/test/test_utils_tls.impl.hpp index 36b8805422..20facabadd 100644 --- a/modules/core/test/test_utils_tls.impl.hpp +++ b/modules/core/test/test_utils_tls.impl.hpp @@ -4,9 +4,7 @@ // This is .hpp file included from test_utils.cpp -#ifdef CV_CXX11 #include // std::thread -#endif #include "opencv2/core/utils/tls.hpp" @@ -34,8 +32,6 @@ public: int TLSReporter::g_last_id = 0; int TLSReporter::g_allocated = 0; -#ifdef CV_CXX11 - template static void callNThreadsWithTLS(int N, TLSData& tls) { @@ -129,6 +125,4 @@ static void testTLSAccumulator(bool detachFirst) TEST(Core_TLS, AccumulatorHoldData_detachData) { testTLSAccumulator(true); } TEST(Core_TLS, AccumulatorHoldData_gather) { testTLSAccumulator(false); } -#endif - }} // namespace diff --git a/modules/dnn/src/net_impl.cpp b/modules/dnn/src/net_impl.cpp index 16ae6d7bfb..09258642f9 100644 --- a/modules/dnn/src/net_impl.cpp +++ b/modules/dnn/src/net_impl.cpp @@ -918,7 +918,6 @@ AsyncArray Net::Impl::forwardAsync(const String& outputName) CV_Assert(!empty()); FPDenormalsIgnoreHintScope fp_denormals_ignore_scope; -#ifdef CV_CXX11 String layerName = outputName; if (layerName.empty()) @@ -939,9 +938,6 @@ AsyncArray Net::Impl::forwardAsync(const String& outputName) isAsync = false; return getBlobAsync(layerName); -#else - CV_Error(Error::StsNotImplemented, "DNN: Asynchronous forward requires build with enabled C++11"); -#endif // CV_CXX11 } diff --git a/modules/dnn/src/net_impl.hpp b/modules/dnn/src/net_impl.hpp index d935655c4a..a11db8fb30 100644 --- a/modules/dnn/src/net_impl.hpp +++ b/modules/dnn/src/net_impl.hpp @@ -273,11 +273,9 @@ struct Net::Impl : public detail::NetImplBase Mat getBlob(String outputName) const; -#ifdef CV_CXX11 virtual AsyncArray getBlobAsync(const LayerPin& pin); AsyncArray getBlobAsync(String outputName); -#endif // CV_CXX11 string dump(bool forceAllocation = false) const; diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index 5afff7db00..72b93dfef3 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -22,6 +22,7 @@ #ifdef HAVE_PROTOBUF +#include #include #include #include diff --git a/modules/dnn/test/test_misc.cpp b/modules/dnn/test/test_misc.cpp index 12d3964196..b4b691e318 100644 --- a/modules/dnn/test/test_misc.cpp +++ b/modules/dnn/test/test_misc.cpp @@ -1035,14 +1035,10 @@ TEST_P(Test_two_inputs, basic) randu(firstInp, 0, 100); randu(secondInp, 0, 100); -#ifndef CV_CXX11 std::vector input_names; input_names.push_back("data"); input_names.push_back("second_input"); net.setInputsNames(input_names); -#else - net.setInputsNames({"data", "second_input"}); -#endif net.setInput(firstInp, "data", kScale); net.setInput(secondInp, "second_input", kScaleInv); net.setPreferableBackend(backendId); diff --git a/modules/imgcodecs/src/loadsave.cpp b/modules/imgcodecs/src/loadsave.cpp index 734f7b516c..79db3ac14d 100644 --- a/modules/imgcodecs/src/loadsave.cpp +++ b/modules/imgcodecs/src/loadsave.cpp @@ -210,15 +210,8 @@ struct ImageCodecInitializer static ImageCodecInitializer& getCodecs() { -#ifdef CV_CXX11 static ImageCodecInitializer g_codecs; return g_codecs; -#else - // C++98 doesn't guarantee correctness of multi-threaded initialization of static global variables - // (memory leak here is not critical, use C++11 to avoid that) - static ImageCodecInitializer* g_codecs = new ImageCodecInitializer(); - return *g_codecs; -#endif } /** diff --git a/modules/objdetect/src/precomp.hpp b/modules/objdetect/src/precomp.hpp index 790a980697..63ca440076 100644 --- a/modules/objdetect/src/precomp.hpp +++ b/modules/objdetect/src/precomp.hpp @@ -52,5 +52,7 @@ #include "opencv2/core/private.hpp" #include +#include +#include #endif diff --git a/modules/objdetect/src/qrcode.cpp b/modules/objdetect/src/qrcode.cpp index dd127b38b0..3590136e3b 100644 --- a/modules/objdetect/src/qrcode.cpp +++ b/modules/objdetect/src/qrcode.cpp @@ -15,6 +15,7 @@ #include "quirc.h" #endif +#include #include #include #include diff --git a/modules/objdetect/test/test_precomp.hpp b/modules/objdetect/test/test_precomp.hpp index 88b8e9a4f5..452a0d78d6 100644 --- a/modules/objdetect/test/test_precomp.hpp +++ b/modules/objdetect/test/test_precomp.hpp @@ -7,10 +7,6 @@ #include "opencv2/ts.hpp" #include "opencv2/objdetect.hpp" -#if defined CV_CXX11 - #include -#else - #include -#endif +#include #endif diff --git a/modules/objdetect/test/test_qrcode_encode.cpp b/modules/objdetect/test/test_qrcode_encode.cpp index 7f5eb37f09..45567b5d9b 100644 --- a/modules/objdetect/test/test_qrcode_encode.cpp +++ b/modules/objdetect/test/test_qrcode_encode.cpp @@ -5,16 +5,6 @@ #include "test_precomp.hpp" namespace opencv_test { namespace { -#if !defined CV_CXX11 -// Wrapper for generating seeded random number via std::rand. -template -class SeededRandFunctor { -public: - SeededRandFunctor() { std::srand(Seed); } - int operator()(int i) { return std::rand() % (i + 1); } -}; -#endif - std::string encode_qrcode_images_name[] = { "version1_mode1.png", "version1_mode2.png", "version1_mode4.png", "version2_mode1.png", "version2_mode2.png", "version2_mode4.png", diff --git a/modules/python/src2/cv2_util.cpp b/modules/python/src2/cv2_util.cpp index d3691d3a59..817a4a8eff 100644 --- a/modules/python/src2/cv2_util.cpp +++ b/modules/python/src2/cv2_util.cpp @@ -128,11 +128,7 @@ void pyPopulateArgumentConversionErrors() PySafeObject exception_message(PyObject_Str(exception_value)); std::string message; getUnicodeString(exception_message, message); -#ifdef CV_CXX11 conversionErrorsTLS.getRef().push_back(std::move(message)); -#else - conversionErrorsTLS.getRef().push_back(message); -#endif } } diff --git a/modules/python/src2/hdr_parser.py b/modules/python/src2/hdr_parser.py index 34bcd585ce..d4a5b26a9f 100755 --- a/modules/python/src2/hdr_parser.py +++ b/modules/python/src2/hdr_parser.py @@ -455,8 +455,7 @@ class CppHeaderParser(object): ("CV_INLINE", ""), ("CV_DEPRECATED", ""), ("CV_DEPRECATED_EXTERNAL", ""), - ("CV_NODISCARD_STD", ""), - ("CV_NODISCARD", "")]).strip() + ("CV_NODISCARD_STD", "")]).strip() if decl_str.strip().startswith('virtual'): virtual_method = True diff --git a/modules/stitching/src/precomp.hpp b/modules/stitching/src/precomp.hpp index debc0d2088..2a1177496a 100644 --- a/modules/stitching/src/precomp.hpp +++ b/modules/stitching/src/precomp.hpp @@ -45,6 +45,7 @@ #include "opencv2/opencv_modules.hpp" +#include #include #include #include diff --git a/modules/ts/include/opencv2/ts.hpp b/modules/ts/include/opencv2/ts.hpp index 86f2d07761..a768d0047b 100644 --- a/modules/ts/include/opencv2/ts.hpp +++ b/modules/ts/include/opencv2/ts.hpp @@ -941,13 +941,9 @@ namespace opencv_test { using namespace cvtest; using namespace cv; -#ifdef CV_CXX11 #define CVTEST_GUARD_SYMBOL(name) \ class required_namespace_specificatin_here_for_symbol_ ## name {}; \ using name = required_namespace_specificatin_here_for_symbol_ ## name; -#else -#define CVTEST_GUARD_SYMBOL(name) /* nothing */ -#endif CVTEST_GUARD_SYMBOL(norm) CVTEST_GUARD_SYMBOL(add) diff --git a/modules/videoio/src/cap_mfx_common.hpp b/modules/videoio/src/cap_mfx_common.hpp index 9824e89dc5..b10d7115ba 100644 --- a/modules/videoio/src/cap_mfx_common.hpp +++ b/modules/videoio/src/cap_mfx_common.hpp @@ -334,26 +334,11 @@ protected: // TODO: move to core::util? -#ifdef CV_CXX11 #include static void sleep_ms(int64 ms) { std::this_thread::sleep_for(std::chrono::milliseconds(ms)); } -#elif defined(__linux__) -#include -static void sleep_ms(int64 ms) -{ - nanosleep(ms * 1000 * 1000); -} -#elif defined _WIN32 -static void sleep_ms(int64 ms) -{ - Sleep(ms); -} -#else -#error "Can not detect sleep_ms() implementation" -#endif // Linux specific diff --git a/modules/videoio/src/cap_msmf.cpp b/modules/videoio/src/cap_msmf.cpp index 6fbcd2aa02..93545c615e 100644 --- a/modules/videoio/src/cap_msmf.cpp +++ b/modules/videoio/src/cap_msmf.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include diff --git a/samples/cpp/tutorial_code/core/how_to_use_OpenCV_parallel_for_/how_to_use_OpenCV_parallel_for_.cpp b/samples/cpp/tutorial_code/core/how_to_use_OpenCV_parallel_for_/how_to_use_OpenCV_parallel_for_.cpp index 2dcc1ff107..5fbe81cd1d 100644 --- a/samples/cpp/tutorial_code/core/how_to_use_OpenCV_parallel_for_/how_to_use_OpenCV_parallel_for_.cpp +++ b/samples/cpp/tutorial_code/core/how_to_use_OpenCV_parallel_for_/how_to_use_OpenCV_parallel_for_.cpp @@ -2,6 +2,8 @@ #include #include +#define PARALLEL_FOR_LAMBDA + using namespace std; using namespace cv; @@ -33,6 +35,8 @@ int mandelbrotFormula(const complex &z0, const int maxIter=500) { } //! [mandelbrot-grayscale-value] +#ifndef PARALLEL_FOR_LAMBDA + //! [mandelbrot-parallel] class ParallelMandelbrot : public ParallelLoopBody { @@ -71,6 +75,8 @@ private: }; //! [mandelbrot-parallel] +#endif // !PARALLEL_FOR_LAMBDA + //! [mandelbrot-sequential] void sequentialMandelbrot(Mat &img, const float x1, const float y1, const float scaleX, const float scaleY) { @@ -102,7 +108,7 @@ int main() double t1 = (double) getTickCount(); - #ifdef CV_CXX11 +#ifdef PARALLEL_FOR_LAMBDA //! [mandelbrot-parallel-call-cxx11] parallel_for_(Range(0, mandelbrotImg.rows*mandelbrotImg.cols), [&](const Range& range){ @@ -121,14 +127,14 @@ int main() }); //! [mandelbrot-parallel-call-cxx11] - #else +#else // PARALLEL_FOR_LAMBDA //! [mandelbrot-parallel-call] ParallelMandelbrot parallelMandelbrot(mandelbrotImg, x1, y1, scaleX, scaleY); parallel_for_(Range(0, mandelbrotImg.rows*mandelbrotImg.cols), parallelMandelbrot); //! [mandelbrot-parallel-call] - #endif +#endif // PARALLEL_FOR_LAMBDA t1 = ((double) getTickCount() - t1) / getTickFrequency(); cout << "Parallel Mandelbrot: " << t1 << " s" << endl; diff --git a/samples/cpp/tutorial_code/core/how_to_use_OpenCV_parallel_for_/how_to_use_OpenCV_parallel_for_new.cpp b/samples/cpp/tutorial_code/core/how_to_use_OpenCV_parallel_for_/how_to_use_OpenCV_parallel_for_new.cpp index cfa9d22b0d..cab73874a4 100644 --- a/samples/cpp/tutorial_code/core/how_to_use_OpenCV_parallel_for_/how_to_use_OpenCV_parallel_for_new.cpp +++ b/samples/cpp/tutorial_code/core/how_to_use_OpenCV_parallel_for_/how_to_use_OpenCV_parallel_for_new.cpp @@ -4,6 +4,8 @@ #include #include +#define PARALLEL_FOR_LAMBDA + using namespace std; using namespace cv; @@ -47,7 +49,8 @@ void conv_seq(Mat src, Mat &dst, Mat kernel) } //! [convolution-sequential] -#ifdef CV_CXX11 +#ifdef PARALLEL_FOR_LAMBDA + void conv_parallel(Mat src, Mat &dst, Mat kernel) { int rows = src.rows, cols = src.cols; @@ -118,7 +121,8 @@ void conv_parallel_row_split(Mat src, Mat &dst, Mat kernel) }); //! [convolution-parallel-cxx11-row-split] } -#else + +#else // PARALLEL_FOR_LAMBDA //! [convolution-parallel] class parallelConvolution : public ParallelLoopBody @@ -235,7 +239,7 @@ void conv_parallel_row_split(Mat src, Mat &dst, Mat kernel) //! [convolution-parallel-function-row] } -#endif +#endif // PARALLEL_FOR_LAMBDA static void help(char *progName) { @@ -329,4 +333,4 @@ int main(int argc, char *argv[]) // imwrite("dst.png", dst); return 0; -} \ No newline at end of file +} diff --git a/samples/cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp b/samples/cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp index ac1c205258..d9e0d1f94d 100644 --- a/samples/cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp +++ b/samples/cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp @@ -59,12 +59,12 @@ int main(int,char**) cout << "C = " << endl << " " << C << endl << endl; //! [comma] // do the same with initializer_list -#ifdef CV_CXX11 + //! [list] C = (Mat_({0, -1, 0, -1, 5, -1, 0, -1, 0})).reshape(3); cout << "C = " << endl << " " << C << endl << endl; //! [list] -#endif + //! [clone] Mat RowClone = C.row(1).clone(); cout << "RowClone = " << endl << " " << RowClone << endl << endl; diff --git a/samples/dnn/object_detection.cpp b/samples/dnn/object_detection.cpp index 6fc8b2ab61..a0c255fd4e 100644 --- a/samples/dnn/object_detection.cpp +++ b/samples/dnn/object_detection.cpp @@ -5,7 +5,7 @@ #include #include -#if defined(CV_CXX11) && defined(HAVE_THREADS) +#if defined(HAVE_THREADS) #define USE_THREADS 1 #endif