Skip to content

Commit 0d7a8cf

Browse files
authored
[SYCL][Doc] Clarify that uniform is immutable (#4246)
We received feedback from the oneAPI TAB that it was not immediately obvious that the uniform class is immutable. The changes here are an attempt to clarify this: - The implicit conversion operator returns "const T", reflecting that the user is not getting a reference to the underlying data. - The assignment operator is deleted, preventing the user from accidentally assigning one uniform object to another. - Other operators that users might accidentally call on a uniform of a fundamental type (e.g. += on a uniform<int>) are explicitly deleted; the intent here is to give a simplified error message (rather than a complex C++ diagnostic) that signals the operator is deliberately not supported (rather than accidentally missing or unimplemented). Signed-off-by: John Pennycook <[email protected]>
1 parent ab675a9 commit 0d7a8cf

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

sycl/doc/extensions/Uniform/Uniform.asciidoc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,28 @@ namespace experimental {
110110
111111
template <class T>
112112
class uniform {
113+
public:
113114
explicit uniform(T x) noexcept;
114-
operator T() const;
115+
operator const T() const;
116+
117+
uniform& operator=(const uniform&) = delete;
118+
119+
/* Other explicitly deleted operators improve error messages
120+
if a user incorrectly attempts to modify a uniform */
121+
uniform& operator+=(const T&) = delete;
122+
uniform& operator-=(const T&) = delete;
123+
uniform& operator*=(const T&) = delete;
124+
uniform& operator/=(const T&) = delete;
125+
uniform& operator%=(const T&) = delete;
126+
uniform& operator&=(const T&) = delete;
127+
uniform& operator|=(const T&) = delete;
128+
uniform& operator^=(const T&) = delete;
129+
uniform& operator<<=(const T&) = delete;
130+
uniform& operator>>=(const T&) = delete;
131+
uniform& operator++() = delete;
132+
uniform& operator++(int) = delete;
133+
uniform& operator--() = delete;
134+
uniform& operator--(int) = delete;
115135
};
116136
117137
} // namespace experimental
@@ -181,6 +201,7 @@ float x = array[sycl::ext::oneapi::experimental::uniform(index)];
181201
|========================================
182202
|Rev|Date|Author|Changes
183203
|1|2021-04-23|John Pennycook|*Initial public working draft*
204+
|2|2021-08-03|John Pennycook|*Add const and deleted operators*
184205
|========================================
185206
186207
//************************************************************************

0 commit comments

Comments
 (0)