Skip to content

Commit 79faf85

Browse files
authored
Merge pull request opencv#26042 from pasbi:add-PtrStepSz_size
Add size() to CUDA PtrStepSz opencv#26042 According to [cppreference.com compiler support table](https://en.cppreference.com/w/cpp/compiler_support/17), `nvcc` supports `[[nodiscard]]` from version 11. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake Related: opencv#25659
1 parent e5790c0 commit 79faf85

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

modules/core/include/opencv2/core/cuda_types.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
#define __CV_CUDA_HOST_DEVICE__
6767
#endif
6868

69+
#include "opencv2/core/cvdef.h"
70+
#include "opencv2/core.hpp"
71+
6972
namespace cv
7073
{
7174
namespace cuda
@@ -124,6 +127,11 @@ namespace cv
124127

125128
int cols;
126129
int rows;
130+
131+
CV_NODISCARD_STD __CV_CUDA_HOST_DEVICE__ Size size() const { return {cols, rows}; }
132+
CV_NODISCARD_STD __CV_CUDA_HOST_DEVICE__ T& operator ()(const Point &pos) { return (*this)(pos.y, pos.x); }
133+
CV_NODISCARD_STD __CV_CUDA_HOST_DEVICE__ const T& operator ()(const Point &pos) const { return (*this)(pos.y, pos.x); }
134+
using PtrStep<T>::operator();
127135
};
128136

129137
typedef PtrStepSz<unsigned char> PtrStepSzb;

modules/core/include/opencv2/core/cvdef.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,11 @@ __CV_ENUM_FLAGS_BITWISE_XOR_EQ (EnumType, EnumType)
747747
# define __has_cpp_attribute(__x) 0
748748
# endif
749749
# if __has_cpp_attribute(nodiscard)
750-
# define CV_NODISCARD_STD [[nodiscard]]
750+
# if defined(__NVCC__) && __CUDACC_VER_MAJOR__ < 12
751+
# define CV_NODISCARD_STD
752+
# else
753+
# define CV_NODISCARD_STD [[nodiscard]]
754+
# endif
751755
# elif __cplusplus >= 201703L
752756
// available when compiler is C++17 compliant
753757
# define CV_NODISCARD_STD [[nodiscard]]

0 commit comments

Comments
 (0)