Skip to content

Commit 3546a78

Browse files
rolandschulzbader
authored andcommitted
[SYCL] Add vector deduction guide
Signed-off-by: Roland Schulz <[email protected]>
1 parent 728b904 commit 3546a78

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

sycl/include/CL/sycl/types.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,13 @@ template <typename Type, int NumElements> class vec {
10671067
template <typename T1, int T2> friend class vec;
10681068
};
10691069

1070+
#ifdef __cpp_deduction_guides
1071+
// all compilers supporting deduction guides also support fold expressions
1072+
template <class T, class... U,
1073+
class = detail::enable_if_t<(std::is_same<T, U>::value && ...)>>
1074+
vec(T, U...)->vec<T, sizeof...(U) + 1>;
1075+
#endif
1076+
10701077
namespace detail {
10711078

10721079
// SwizzleOP represents expression templates that operate on vec.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %clangxx -std=c++17 -fsyntax-only -Xclang -verify %s
2+
// expected-no-diagnostics
3+
//==--------------- ctad.cpp - SYCL vector CTAD test --------------------==//
4+
//
5+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6+
// See https://llvm.org/LICENSE.txt for license information.
7+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
//
9+
//===----------------------------------------------------------------------===//
10+
#include <CL/sycl.hpp>
11+
12+
namespace sycl = cl::sycl;
13+
14+
int main() {
15+
sycl::vec v1(1);
16+
static_assert(std::is_same_v<decltype(v1), sycl::vec<int, 1>>);
17+
sycl::vec v2(1, 2);
18+
static_assert(std::is_same_v<decltype(v2), sycl::vec<int, 2>>);
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clangxx -std=c++17 -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected %s
2+
//==--------------- ctad.cpp - SYCL vector CTAD fail test ------------------==//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
#include <CL/sycl.hpp>
10+
11+
namespace sycl = cl::sycl;
12+
13+
int main() {
14+
sycl::vec v(1, .1); // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'vec'}}
15+
}

0 commit comments

Comments
 (0)