Skip to content

Commit

Permalink
small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
wangdi4 committed Jan 10, 2024
1 parent 1c00e8d commit a5d3d8f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ the given alignment, specified in bytes. The behavior is undefined if the
pointer value does not have the indicated alignment.


When alignment is specified on `annotated_ptr`, the `operator+`, `operator-`, `operator[]`,
`operator++`,`operator++(int)`,`operator--` and `operator--(int)` are disabled.
When alignment is specified on `annotated_ptr`, the operators `+`, `[]`,
`++`, and `--` (both post- and prefix) are disabled.

|===
--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,22 @@ __SYCL_TYPE(annotated_ptr) annotated_ptr<T, detail::properties_t<Props...>> {

reference operator*() const noexcept { return reference(m_Ptr); }

std::ptrdiff_t operator-(annotated_ptr other) const noexcept {
return m_Ptr - other.m_Ptr;
}

explicit operator bool() const noexcept { return m_Ptr != nullptr; }

operator T *() const noexcept = delete;

T *get() const noexcept { return m_Ptr; }

// When the properties contain alignment, operator '[]', '+', '++' and '--'
// (both post- and prefix) are disabled. Calling these operators when
// alignment is present causes a compile error. Note that clang format is
// turned off for these operators to make sure the complete error notes are
// printed
// clang-format off
template <bool has_alignment = detail::contains_alignment<Props...>::value,
class = std::enable_if_t<!has_alignment>>
reference operator[](std::ptrdiff_t idx) const noexcept {
Expand All @@ -376,9 +392,7 @@ __SYCL_TYPE(annotated_ptr) annotated_ptr<T, detail::properties_t<Props...>> {

template <bool has_alignment = detail::contains_alignment<Props...>::value,
class = std::enable_if_t<has_alignment>>
auto operator[](std::ptrdiff_t idx) const noexcept
-> decltype("operator[] is not available when alignment is specified!") =
delete;
auto operator[](std::ptrdiff_t idx) const noexcept -> decltype("operator[] is not available when alignment is specified!") = delete;

template <bool has_alignment = detail::contains_alignment<Props...>::value,
class = std::enable_if_t<!has_alignment>>
Expand All @@ -388,19 +402,7 @@ __SYCL_TYPE(annotated_ptr) annotated_ptr<T, detail::properties_t<Props...>> {

template <bool has_alignment = detail::contains_alignment<Props...>::value,
class = std::enable_if_t<has_alignment>>
auto operator+(size_t offset) const noexcept
-> decltype("operator+ is not available when alignment is specified!") =
delete;

std::ptrdiff_t operator-(annotated_ptr other) const noexcept {
return m_Ptr - other.m_Ptr;
}

explicit operator bool() const noexcept { return m_Ptr != nullptr; }

operator T *() const noexcept = delete;

T *get() const noexcept { return m_Ptr; }
auto operator+(size_t offset) const noexcept -> decltype("operator+ is not available when alignment is specified!") = delete;

template <bool has_alignment = detail::contains_alignment<Props...>::value,
class = std::enable_if_t<!has_alignment>>
Expand All @@ -411,23 +413,19 @@ __SYCL_TYPE(annotated_ptr) annotated_ptr<T, detail::properties_t<Props...>> {

template <bool has_alignment = detail::contains_alignment<Props...>::value,
class = std::enable_if_t<has_alignment>>
auto operator++() noexcept
-> decltype("operator++ is not available when alignment is specified!") =
delete;
auto operator++() noexcept -> decltype("operator++ is not available when alignment is specified!") = delete;

template <bool has_alignment = detail::contains_alignment<Props...>::value,
class = std::enable_if_t<!has_alignment>>
annotated_ptr &operator++(int) noexcept {
annotated_ptr operator++(int) noexcept {
auto tmp = *this;
m_Ptr += 1;
return tmp;
}

template <bool has_alignment = detail::contains_alignment<Props...>::value,
class = std::enable_if_t<has_alignment>>
auto operator++(int) noexcept
-> decltype("operator++ is not available when alignment is specified!") =
delete;
auto operator++(int) noexcept -> decltype("operator++ is not available when alignment is specified!") = delete;

template <bool has_alignment = detail::contains_alignment<Props...>::value,
class = std::enable_if_t<!has_alignment>>
Expand All @@ -438,25 +436,21 @@ __SYCL_TYPE(annotated_ptr) annotated_ptr<T, detail::properties_t<Props...>> {

template <bool has_alignment = detail::contains_alignment<Props...>::value,
class = std::enable_if_t<has_alignment>>
auto operator--() noexcept
-> decltype("operator-- is not available when alignment is specified!") =
delete;
auto operator--() noexcept -> decltype("operator-- is not available when alignment is specified!") = delete;

template <bool has_alignment = detail::contains_alignment<Props...>::value,
class = std::enable_if_t<!has_alignment>>
annotated_ptr &operator--(int) noexcept {
annotated_ptr operator--(int) noexcept {
auto tmp = *this;
m_Ptr -= 1;
return tmp;
}

template <bool has_alignment = detail::contains_alignment<Props...>::value,
class = std::enable_if_t<has_alignment>>
auto operator--(int) noexcept
-> decltype("operator-- is not available when alignment is specified!") =
delete;
auto operator--(int) noexcept -> decltype("operator-- is not available when alignment is specified!") = delete;

#undef MSG_OP_NOT_SUPPORTED
// clang-format on

template <typename PropertyT> static constexpr bool has_property() {
return property_list_t::template has_property<PropertyT>();
Expand Down

0 comments on commit a5d3d8f

Please sign in to comment.