// SPDX-License-Identifier: MIT // Copyright (c) 2018-2025, Advanced Micro Devices, Inc. All rights reserved. #pragma once #include "ck/utility/integral_constant.hpp" #include "ck/utility/type.hpp" namespace ck { // TODO: right? wrong? struct forwarder { template __host__ __device__ constexpr T&& operator()(T&& x) const { return static_cast(x); } }; struct swallow { template __host__ __device__ constexpr swallow(Ts&&...) { } }; template struct logical_and { constexpr bool operator()(const T& x, const T& y) const { return x && y; } }; template struct logical_or { constexpr bool operator()(const T& x, const T& y) const { return x || y; } }; template struct logical_not { constexpr bool operator()(const T& x) const { return !x; } }; // Emulate if constexpr template struct static_if; template <> struct static_if { using Type = static_if; template __host__ __device__ constexpr auto operator()(F f) const { // This is a trick for compiler: // Pass forwarder to lambda "f" as "auto" argument, and make sure "f" will // use it, // this will make "f" a generic lambda, so that "f" won't be compiled // until being // instantiated here f(forwarder{}); return Type{}; } template __host__ __device__ static void Else(F) { } }; template <> struct static_if { using Type = static_if; template __host__ __device__ constexpr auto operator()(F) const { return Type{}; } template __host__ __device__ static void Else(F f) { // This is a trick for compiler: // Pass forwarder to lambda "f" as "auto" argument, and make sure "f" will // use it, // this will make "f" a generic lambda, so that "f" won't be compiled // until being // instantiated here f(forwarder{}); } }; template struct conditional; template struct conditional { using type = X; }; template struct conditional { using type = Y; }; template using conditional_t = typename conditional::type; // z = predicate ? x : y template constexpr auto conditional_expr(X&& x, Y&& y) { if constexpr(predicate) { return ck::forward(x); } else { return ck::forward(y); } } } // namespace ck