|
| 1 | +/* Copyright 2025 Tapish Narwal |
| 2 | + * |
| 3 | + * This file is part of PMacc. |
| 4 | + * |
| 5 | + * PMacc is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of either the GNU General Public License or |
| 7 | + * the GNU Lesser General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * PMacc is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License and the GNU Lesser General Public License |
| 15 | + * for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * and the GNU Lesser General Public License along with PMacc. |
| 19 | + * If not, see <http://www.gnu.org/licenses/>. |
| 20 | + */ |
| 21 | + |
| 22 | +#pragma once |
| 23 | + |
| 24 | +#include <type_traits> |
| 25 | + |
| 26 | +namespace pmacc |
| 27 | +{ |
| 28 | + namespace traits |
| 29 | + { |
| 30 | + |
| 31 | + /** |
| 32 | + * Type trait to check if a type is a specialization of a template |
| 33 | + * Similar to P2078 - https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2098r0.pdf |
| 34 | + * Note that this cant be used with template types which have NTTPs |
| 35 | + * To fix this limitation we need PR1985 Universal Template Parameters |
| 36 | + * https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1985r3.pdf |
| 37 | + */ |
| 38 | + |
| 39 | + template<typename, template<typename...> typename> |
| 40 | + struct IsSpecializationOf : std::false_type |
| 41 | + { |
| 42 | + }; |
| 43 | + |
| 44 | + template<template<typename...> typename Template, typename... Args> |
| 45 | + struct IsSpecializationOf<Template<Args...>, Template> : std::true_type |
| 46 | + { |
| 47 | + }; |
| 48 | + |
| 49 | + } // namespace traits |
| 50 | + |
| 51 | + template<typename T, template<typename...> typename Template> |
| 52 | + inline constexpr bool isSpecializationOf_v = traits::IsSpecializationOf<T, Template>::value; |
| 53 | + |
| 54 | + namespace concepts |
| 55 | + { |
| 56 | + template<typename T, template<typename...> typename Template> |
| 57 | + concept SpecializationOf = isSpecializationOf_v<T, Template>; |
| 58 | + |
| 59 | + } // namespace concepts |
| 60 | + |
| 61 | +} // namespace pmacc |
0 commit comments