From 10ae0c4364ecf1bebf3a80f7a6570142e4da7632 Mon Sep 17 00:00:00 2001 From: Hamdi Sahloul <42140441+cv3d@users.noreply.github.com> Date: Wed, 12 Sep 2018 04:35:03 +0900 Subject: [PATCH] Merge pull request #12486 from cv3d:fix_cpp11 Support MSVC 2013 (#12486) * Added CV_CONSTEXPR macro * Utilize CV_NOEXCEPT and CV_CONSTEXPR * Provides some Ptr<> logical operators --- modules/core/include/opencv2/core/cvdef.h | 8 +++ .../include/opencv2/core/cvstd_wrapper.hpp | 38 ++++++------- modules/dnn/src/op_inf_engine.cpp | 56 +++++++++---------- modules/dnn/src/op_inf_engine.hpp | 56 +++++++++---------- 4 files changed, 83 insertions(+), 75 deletions(-) diff --git a/modules/core/include/opencv2/core/cvdef.h b/modules/core/include/opencv2/core/cvdef.h index 21fce842a8..8c4ae7d9f9 100644 --- a/modules/core/include/opencv2/core/cvdef.h +++ b/modules/core/include/opencv2/core/cvdef.h @@ -456,6 +456,14 @@ Cv64suf; # define CV_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 const +#endif // Integer types portatibility #ifdef OPENCV_STDINT_HEADER diff --git a/modules/core/include/opencv2/core/cvstd_wrapper.hpp b/modules/core/include/opencv2/core/cvstd_wrapper.hpp index 358a47eb4b..0a30432dbb 100644 --- a/modules/core/include/opencv2/core/cvstd_wrapper.hpp +++ b/modules/core/include/opencv2/core/cvstd_wrapper.hpp @@ -43,14 +43,14 @@ struct has_parenthesis_operator { private: template - static constexpr std::true_type check(typename std::is_same().operator()(std::declval()...))>::type, Ret>::type*); + static CV_CONSTEXPR std::true_type check(typename std::is_same().operator()(std::declval()...))>::type, Ret>::type*); - template static constexpr std::false_type check(...); + template static CV_CONSTEXPR std::false_type check(...); typedef decltype(check(0)) type; public: - static constexpr bool value = type::value; + static CV_CONSTEXPR bool value = type::value; }; } // namespace sfinae @@ -62,21 +62,21 @@ struct Ptr : public std::shared_ptr #if 0 using std::shared_ptr::shared_ptr; // GCC 5.x can't handle this #else - inline Ptr() noexcept : std::shared_ptr() {} - inline Ptr(nullptr_t) noexcept : std::shared_ptr(nullptr) {} + inline Ptr() CV_NOEXCEPT : std::shared_ptr() {} + inline Ptr(nullptr_t) CV_NOEXCEPT : std::shared_ptr(nullptr) {} template inline Ptr(Y* p, D d) : std::shared_ptr(p, d) {} template inline Ptr(nullptr_t, D d) : std::shared_ptr(nullptr, d) {} - template inline Ptr(const Ptr& r, T* ptr) noexcept : std::shared_ptr(r, ptr) {} + template inline Ptr(const Ptr& r, T* ptr) CV_NOEXCEPT : std::shared_ptr(r, ptr) {} - inline Ptr(const Ptr& o) noexcept : std::shared_ptr(o) {} - inline Ptr(Ptr&& o) noexcept : std::shared_ptr(std::move(o)) {} + inline Ptr(const Ptr& o) CV_NOEXCEPT : std::shared_ptr(o) {} + inline Ptr(Ptr&& o) CV_NOEXCEPT : std::shared_ptr(std::move(o)) {} - template inline Ptr(const Ptr& o) noexcept : std::shared_ptr(o) {} - template inline Ptr(Ptr&& o) noexcept : std::shared_ptr(std::move(o)) {} + template inline Ptr(const Ptr& o) CV_NOEXCEPT : std::shared_ptr(o) {} + template inline Ptr(Ptr&& o) CV_NOEXCEPT : std::shared_ptr(std::move(o)) {} #endif - inline Ptr(const std::shared_ptr& o) noexcept : std::shared_ptr(o) {} - inline Ptr(std::shared_ptr&& o) noexcept : std::shared_ptr(std::move(o)) {} + 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(...) @@ -105,27 +105,27 @@ struct Ptr : public std::shared_ptr template void reset(Y* ptr, Deleter d) { std::shared_ptr::reset(ptr, d); } - void reset() noexcept { std::shared_ptr::reset(); } + void reset() CV_NOEXCEPT { std::shared_ptr::reset(); } Ptr& operator=(const Ptr& o) { std::shared_ptr::operator =(o); return *this; } template inline Ptr& operator=(const Ptr& o) { std::shared_ptr::operator =(o); return *this; } - T* operator->() const noexcept { return std::shared_ptr::get();} - typename std::add_lvalue_reference::type operator*() const noexcept { return *std::shared_ptr::get(); } + T* operator->() const CV_NOEXCEPT { return std::shared_ptr::get();} + typename std::add_lvalue_reference::type operator*() const CV_NOEXCEPT { return *std::shared_ptr::get(); } // OpenCV 3.x methods (not a part of standart C++ library) inline void release() { std::shared_ptr::reset(); } inline operator T* () const { return std::shared_ptr::get(); } - inline bool empty() const { return std::shared_ptr::get() == NULL; } + inline bool empty() const { return std::shared_ptr::get() == nullptr; } template inline - Ptr staticCast() const noexcept { return std::static_pointer_cast(*this); } + Ptr staticCast() const CV_NOEXCEPT { return std::static_pointer_cast(*this); } template inline - Ptr constCast() const noexcept { return std::const_pointer_cast(*this); } + Ptr constCast() const CV_NOEXCEPT { return std::const_pointer_cast(*this); } template inline - Ptr dynamicCast() const noexcept { return std::dynamic_pointer_cast(*this); } + Ptr dynamicCast() const CV_NOEXCEPT { return std::dynamic_pointer_cast(*this); } }; template static inline diff --git a/modules/dnn/src/op_inf_engine.cpp b/modules/dnn/src/op_inf_engine.cpp index 85f6690790..04de1ee07f 100644 --- a/modules/dnn/src/op_inf_engine.cpp +++ b/modules/dnn/src/op_inf_engine.cpp @@ -164,92 +164,92 @@ InfEngineBackendNet::InfEngineBackendNet(InferenceEngine::CNNNetwork& net) netOwner = net; } -void InfEngineBackendNet::Release() noexcept +void InfEngineBackendNet::Release() CV_NOEXCEPT { layers.clear(); inputs.clear(); outputs.clear(); } -void InfEngineBackendNet::setPrecision(InferenceEngine::Precision p) noexcept +void InfEngineBackendNet::setPrecision(InferenceEngine::Precision p) CV_NOEXCEPT { precision = p; } -InferenceEngine::Precision InfEngineBackendNet::getPrecision() noexcept +InferenceEngine::Precision InfEngineBackendNet::getPrecision() CV_NOEXCEPT { return precision; } -InferenceEngine::Precision InfEngineBackendNet::getPrecision() const noexcept +InferenceEngine::Precision InfEngineBackendNet::getPrecision() const CV_NOEXCEPT { return precision; } // Assume that outputs of network is unconnected blobs. -void InfEngineBackendNet::getOutputsInfo(InferenceEngine::OutputsDataMap &outputs_) noexcept +void InfEngineBackendNet::getOutputsInfo(InferenceEngine::OutputsDataMap &outputs_) CV_NOEXCEPT { const_cast(this)->getOutputsInfo(outputs_); } -void InfEngineBackendNet::getOutputsInfo(InferenceEngine::OutputsDataMap &outputs_) const noexcept +void InfEngineBackendNet::getOutputsInfo(InferenceEngine::OutputsDataMap &outputs_) const CV_NOEXCEPT { outputs_ = outputs; } // Returns input references that aren't connected to internal outputs. -void InfEngineBackendNet::getInputsInfo(InferenceEngine::InputsDataMap &inputs_) noexcept +void InfEngineBackendNet::getInputsInfo(InferenceEngine::InputsDataMap &inputs_) CV_NOEXCEPT { const_cast(this)->getInputsInfo(inputs_); } // Returns input references that aren't connected to internal outputs. -void InfEngineBackendNet::getInputsInfo(InferenceEngine::InputsDataMap &inputs_) const noexcept +void InfEngineBackendNet::getInputsInfo(InferenceEngine::InputsDataMap &inputs_) const CV_NOEXCEPT { inputs_ = inputs; } -InferenceEngine::InputInfo::Ptr InfEngineBackendNet::getInput(const std::string &inputName) noexcept +InferenceEngine::InputInfo::Ptr InfEngineBackendNet::getInput(const std::string &inputName) CV_NOEXCEPT { return const_cast(this)->getInput(inputName); } -InferenceEngine::InputInfo::Ptr InfEngineBackendNet::getInput(const std::string &inputName) const noexcept +InferenceEngine::InputInfo::Ptr InfEngineBackendNet::getInput(const std::string &inputName) const CV_NOEXCEPT { const auto& it = inputs.find(inputName); CV_Assert(it != inputs.end()); return it->second; } -void InfEngineBackendNet::getName(char*, size_t) noexcept +void InfEngineBackendNet::getName(char*, size_t) CV_NOEXCEPT { } -void InfEngineBackendNet::getName(char*, size_t) const noexcept +void InfEngineBackendNet::getName(char*, size_t) const CV_NOEXCEPT { } -const std::string& InfEngineBackendNet::getName() const noexcept +const std::string& InfEngineBackendNet::getName() const CV_NOEXCEPT { return name; } -size_t InfEngineBackendNet::layerCount() noexcept +size_t InfEngineBackendNet::layerCount() CV_NOEXCEPT { return const_cast(this)->layerCount(); } -size_t InfEngineBackendNet::layerCount() const noexcept +size_t InfEngineBackendNet::layerCount() const CV_NOEXCEPT { return layers.size(); } -InferenceEngine::DataPtr& InfEngineBackendNet::getData(const char *dname) noexcept +InferenceEngine::DataPtr& InfEngineBackendNet::getData(const char *dname) CV_NOEXCEPT { CV_Error(Error::StsNotImplemented, ""); return outputs.begin()->second; // Just return something. } -void InfEngineBackendNet::addLayer(const InferenceEngine::CNNLayerPtr &layer) noexcept +void InfEngineBackendNet::addLayer(const InferenceEngine::CNNLayerPtr &layer) CV_NOEXCEPT { layers.push_back(layer); inputs.clear(); @@ -258,7 +258,7 @@ void InfEngineBackendNet::addLayer(const InferenceEngine::CNNLayerPtr &layer) no InferenceEngine::StatusCode InfEngineBackendNet::addOutput(const std::string &layerName, size_t outputIndex, - InferenceEngine::ResponseDesc *resp) noexcept + InferenceEngine::ResponseDesc *resp) CV_NOEXCEPT { for (const auto& l : layers) { @@ -277,14 +277,14 @@ InfEngineBackendNet::addOutput(const std::string &layerName, size_t outputIndex, InferenceEngine::StatusCode InfEngineBackendNet::getLayerByName(const char *layerName, InferenceEngine::CNNLayerPtr &out, - InferenceEngine::ResponseDesc *resp) noexcept + InferenceEngine::ResponseDesc *resp) CV_NOEXCEPT { return const_cast(this)->getLayerByName(layerName, out, resp); } InferenceEngine::StatusCode InfEngineBackendNet::getLayerByName(const char *layerName, InferenceEngine::CNNLayerPtr &out, - InferenceEngine::ResponseDesc *resp) const noexcept + InferenceEngine::ResponseDesc *resp) const CV_NOEXCEPT { for (auto& l : layers) { @@ -298,7 +298,7 @@ InferenceEngine::StatusCode InfEngineBackendNet::getLayerByName(const char *laye return InferenceEngine::StatusCode::NOT_FOUND; } -void InfEngineBackendNet::setTargetDevice(InferenceEngine::TargetDevice device) noexcept +void InfEngineBackendNet::setTargetDevice(InferenceEngine::TargetDevice device) CV_NOEXCEPT { if (device != InferenceEngine::TargetDevice::eCPU && device != InferenceEngine::TargetDevice::eGPU && @@ -307,42 +307,42 @@ void InfEngineBackendNet::setTargetDevice(InferenceEngine::TargetDevice device) targetDevice = device; } -InferenceEngine::TargetDevice InfEngineBackendNet::getTargetDevice() noexcept +InferenceEngine::TargetDevice InfEngineBackendNet::getTargetDevice() CV_NOEXCEPT { return targetDevice; } -InferenceEngine::TargetDevice InfEngineBackendNet::getTargetDevice() const noexcept +InferenceEngine::TargetDevice InfEngineBackendNet::getTargetDevice() const CV_NOEXCEPT { return targetDevice; } -InferenceEngine::StatusCode InfEngineBackendNet::setBatchSize(const size_t) noexcept +InferenceEngine::StatusCode InfEngineBackendNet::setBatchSize(const size_t) CV_NOEXCEPT { CV_Error(Error::StsNotImplemented, ""); return InferenceEngine::StatusCode::OK; } -InferenceEngine::StatusCode InfEngineBackendNet::setBatchSize(size_t size, InferenceEngine::ResponseDesc *responseDesc) noexcept +InferenceEngine::StatusCode InfEngineBackendNet::setBatchSize(size_t size, InferenceEngine::ResponseDesc *responseDesc) CV_NOEXCEPT { CV_Error(Error::StsNotImplemented, ""); return InferenceEngine::StatusCode::OK; } -size_t InfEngineBackendNet::getBatchSize() const noexcept +size_t InfEngineBackendNet::getBatchSize() const CV_NOEXCEPT { CV_Error(Error::StsNotImplemented, ""); return 0; } #if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2018R2) -InferenceEngine::StatusCode InfEngineBackendNet::AddExtension(const InferenceEngine::IShapeInferExtensionPtr &extension, InferenceEngine::ResponseDesc *resp) noexcept +InferenceEngine::StatusCode InfEngineBackendNet::AddExtension(const InferenceEngine::IShapeInferExtensionPtr &extension, InferenceEngine::ResponseDesc *resp) CV_NOEXCEPT { CV_Error(Error::StsNotImplemented, ""); return InferenceEngine::StatusCode::OK; } -InferenceEngine::StatusCode InfEngineBackendNet::reshape(const InferenceEngine::ICNNNetwork::InputShapes &inputShapes, InferenceEngine::ResponseDesc *resp) noexcept +InferenceEngine::StatusCode InfEngineBackendNet::reshape(const InferenceEngine::ICNNNetwork::InputShapes &inputShapes, InferenceEngine::ResponseDesc *resp) CV_NOEXCEPT { CV_Error(Error::StsNotImplemented, ""); return InferenceEngine::StatusCode::OK; diff --git a/modules/dnn/src/op_inf_engine.hpp b/modules/dnn/src/op_inf_engine.hpp index f04a5c636c..34d4755765 100644 --- a/modules/dnn/src/op_inf_engine.hpp +++ b/modules/dnn/src/op_inf_engine.hpp @@ -47,67 +47,67 @@ public: InfEngineBackendNet(InferenceEngine::CNNNetwork& net); - virtual void Release() noexcept CV_OVERRIDE; + virtual void Release() CV_NOEXCEPT CV_OVERRIDE; - void setPrecision(InferenceEngine::Precision p) noexcept; + void setPrecision(InferenceEngine::Precision p) CV_NOEXCEPT; - virtual InferenceEngine::Precision getPrecision() noexcept; + virtual InferenceEngine::Precision getPrecision() CV_NOEXCEPT; - virtual InferenceEngine::Precision getPrecision() const noexcept; + virtual InferenceEngine::Precision getPrecision() const CV_NOEXCEPT; - virtual void getOutputsInfo(InferenceEngine::OutputsDataMap &out) noexcept /*CV_OVERRIDE*/; + virtual void getOutputsInfo(InferenceEngine::OutputsDataMap &out) CV_NOEXCEPT /*CV_OVERRIDE*/; - virtual void getOutputsInfo(InferenceEngine::OutputsDataMap &out) const noexcept /*CV_OVERRIDE*/; + virtual void getOutputsInfo(InferenceEngine::OutputsDataMap &out) const CV_NOEXCEPT /*CV_OVERRIDE*/; - virtual void getInputsInfo(InferenceEngine::InputsDataMap &inputs) noexcept /*CV_OVERRIDE*/; + virtual void getInputsInfo(InferenceEngine::InputsDataMap &inputs) CV_NOEXCEPT /*CV_OVERRIDE*/; - virtual void getInputsInfo(InferenceEngine::InputsDataMap &inputs) const noexcept /*CV_OVERRIDE*/; + virtual void getInputsInfo(InferenceEngine::InputsDataMap &inputs) const CV_NOEXCEPT /*CV_OVERRIDE*/; - virtual InferenceEngine::InputInfo::Ptr getInput(const std::string &inputName) noexcept; + virtual InferenceEngine::InputInfo::Ptr getInput(const std::string &inputName) CV_NOEXCEPT; - virtual InferenceEngine::InputInfo::Ptr getInput(const std::string &inputName) const noexcept; + virtual InferenceEngine::InputInfo::Ptr getInput(const std::string &inputName) const CV_NOEXCEPT; - virtual void getName(char *pName, size_t len) noexcept; + virtual void getName(char *pName, size_t len) CV_NOEXCEPT; - virtual void getName(char *pName, size_t len) const noexcept; + virtual void getName(char *pName, size_t len) const CV_NOEXCEPT; - virtual const std::string& getName() const noexcept; + virtual const std::string& getName() const CV_NOEXCEPT; - virtual size_t layerCount() noexcept; + virtual size_t layerCount() CV_NOEXCEPT; - virtual size_t layerCount() const noexcept; + virtual size_t layerCount() const CV_NOEXCEPT; - virtual InferenceEngine::DataPtr& getData(const char *dname) noexcept CV_OVERRIDE; + virtual InferenceEngine::DataPtr& getData(const char *dname) CV_NOEXCEPT CV_OVERRIDE; - virtual void addLayer(const InferenceEngine::CNNLayerPtr &layer) noexcept CV_OVERRIDE; + virtual void addLayer(const InferenceEngine::CNNLayerPtr &layer) CV_NOEXCEPT CV_OVERRIDE; virtual InferenceEngine::StatusCode addOutput(const std::string &layerName, size_t outputIndex = 0, - InferenceEngine::ResponseDesc *resp = nullptr) noexcept; + InferenceEngine::ResponseDesc *resp = nullptr) CV_NOEXCEPT; virtual InferenceEngine::StatusCode getLayerByName(const char *layerName, InferenceEngine::CNNLayerPtr &out, - InferenceEngine::ResponseDesc *resp) noexcept; + InferenceEngine::ResponseDesc *resp) CV_NOEXCEPT; virtual InferenceEngine::StatusCode getLayerByName(const char *layerName, InferenceEngine::CNNLayerPtr &out, - InferenceEngine::ResponseDesc *resp) const noexcept; + InferenceEngine::ResponseDesc *resp) const CV_NOEXCEPT; - virtual void setTargetDevice(InferenceEngine::TargetDevice device) noexcept CV_OVERRIDE; + virtual void setTargetDevice(InferenceEngine::TargetDevice device) CV_NOEXCEPT CV_OVERRIDE; - virtual InferenceEngine::TargetDevice getTargetDevice() noexcept; + virtual InferenceEngine::TargetDevice getTargetDevice() CV_NOEXCEPT; - virtual InferenceEngine::TargetDevice getTargetDevice() const noexcept; + virtual InferenceEngine::TargetDevice getTargetDevice() const CV_NOEXCEPT; - virtual InferenceEngine::StatusCode setBatchSize(const size_t size) noexcept CV_OVERRIDE; + virtual InferenceEngine::StatusCode setBatchSize(const size_t size) CV_NOEXCEPT CV_OVERRIDE; - virtual InferenceEngine::StatusCode setBatchSize(size_t size, InferenceEngine::ResponseDesc* responseDesc) noexcept; + virtual InferenceEngine::StatusCode setBatchSize(size_t size, InferenceEngine::ResponseDesc* responseDesc) CV_NOEXCEPT; - virtual size_t getBatchSize() const noexcept CV_OVERRIDE; + virtual size_t getBatchSize() const CV_NOEXCEPT CV_OVERRIDE; #if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2018R2) - virtual InferenceEngine::StatusCode AddExtension(const InferenceEngine::IShapeInferExtensionPtr& extension, InferenceEngine::ResponseDesc* resp) noexcept; - virtual InferenceEngine::StatusCode reshape(const InputShapes& inputShapes, InferenceEngine::ResponseDesc* resp) noexcept; + virtual InferenceEngine::StatusCode AddExtension(const InferenceEngine::IShapeInferExtensionPtr& extension, InferenceEngine::ResponseDesc* resp) CV_NOEXCEPT; + virtual InferenceEngine::StatusCode reshape(const InputShapes& inputShapes, InferenceEngine::ResponseDesc* resp) CV_NOEXCEPT; #endif void init(int targetId);