alpaka
Abstraction Library for Parallel Kernel Acceleration
Unique.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Benjamin Worpitz, Bernhard Manfred Gruber
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
7 #include <type_traits>
8 
9 namespace alpaka::meta
10 {
11  namespace detail
12  {
13  template<typename T, typename... Ts>
14  struct UniqueHelper
15  {
16  using type = T;
17  };
18 
19  template<template<typename...> class TList, typename... Ts, typename U, typename... Us>
20  struct UniqueHelper<TList<Ts...>, U, Us...>
21  : std::conditional_t<
22  (std::is_same_v<U, Ts> || ...),
23  UniqueHelper<TList<Ts...>, Us...>,
24  UniqueHelper<TList<Ts..., U>, Us...>>
25  {
26  };
27 
28  template<typename T>
29  struct UniqueImpl;
30 
31  template<template<typename...> class TList, typename... Ts>
32  struct UniqueImpl<TList<Ts...>>
33  {
34  using type = typename UniqueHelper<TList<>, Ts...>::type;
35  };
36  } // namespace detail
37 
38  //! Trait that returns a list with only unique (no equal) types (a set). Duplicates will be filtered out.
39  template<typename TList>
41 } // namespace alpaka::meta
typename detail::UniqueImpl< TList >::type Unique
Trait that returns a list with only unique (no equal) types (a set). Duplicates will be filtered out.
Definition: Unique.hpp:40
typename UniqueHelper< TList<>, Ts... >::type type
Definition: Unique.hpp:34