//============================================================================ // Copyright (c) Kitware, Inc. // All rights reserved. // See LICENSE.txt for details. // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ $# This file uses the pyexpander macro processing utility to build the $# FunctionInterface facilities that use a variable number of arguments. $# Information, documentation, and downloads for pyexpander can be found at: $# $# http://pyexpander.sourceforge.net/ $# $# To build the source code, execute the following (after installing $# pyexpander, of course): $# $# expander.py VariantDetail.h.in > VariantDetail.h $# $# Ignore the following comment. It is meant for the generated file. // **** DO NOT EDIT THIS FILE!!! **** // This file is automatically generated by VariantDetail.h.in #if !defined(VTK_M_DEVICE) || !defined(VTK_M_NAMESPACE) #error VarianImplDetail.h must be included from VariantImpl.h // Some defines to make my IDE happy. #define VTK_M_DEVICE #define VTK_M_NAMESPACE tmp #endif #include #include #include $py(max_expanded=20)\ $# Python commands used in template expansion. $py( def type_list(num_params): if num_params < 0: return '' result = 'T0' for param in range(1, num_params + 1): result += ', T%d' % param return result )\ $# $extend(type_list)\ namespace vtkm { namespace VTK_M_NAMESPACE { namespace internal { namespace detail { template struct VariantDummyReturn { VTK_M_DEVICE static inline ReturnType F() noexcept { return ReturnType{}; } }; template <> struct VariantDummyReturn { VTK_M_DEVICE static inline void F() noexcept {} }; template VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(brigand::list<>, vtkm::IdComponent, Functor&&, const void*, Args&&...) noexcept { // If we are here, it means we failed to find the appropriate type in a variant VTKM_ASSERT(false && "Internal error, bad Variant state."); return VariantDummyReturn::F(); } // clang-format off $for(num_params in range(0, max_expanded))\ template VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl( brigand::list<$type_list(num_params)>, vtkm::IdComponent index, Functor&& f, const void* storage, Args&&... args) noexcept(noexcept(f(std::declval(), args...))) { switch (index) { $for(param_index in range(0, num_params + 1))\ case $(param_index): return f(*reinterpret_cast(storage), std::forward(args)...); $endfor\ default: // If we are here, it means we failed to find the appropriate type in a variant VTKM_ASSERT(false && "Internal error, bad Variant state."); return VariantDummyReturn::F(); } } template VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl( brigand::list<$type_list(num_params)>, vtkm::IdComponent index, Functor&& f, void* storage, Args&&... args) noexcept(noexcept(f(std::declval(), args...))) { switch (index) { $for(param_index in range(0, num_params + 1))\ case $(param_index): return f(*reinterpret_cast(storage), std::forward(args)...); $endfor\ default: // If we are here, it means we failed to find the appropriate type in a variant VTKM_ASSERT(false && "Internal error, bad Variant state."); return VariantDummyReturn::F(); } } $endfor\ //clang-format on // Recurse for cases where Variant has more than $(max_expanded) types template VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl( brigand::list<$type_list(max_expanded), RemainingT...>, vtkm::IdComponent index, Functor&& f, const void* storage, Args&&... args) noexcept(noexcept(f(std::declval(), args...))) { if (index < $(max_expanded)) { return VariantCastAndCallImpl( brigand::list<$type_list(max_expanded - 1)>{}, index, f, storage, args...); } else { return VariantCastAndCallImpl( brigand::list{}, index - $(max_expanded), f, storage, args...); } } template VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl( brigand::list<$type_list(max_expanded), RemainingT...>, vtkm::IdComponent index, Functor&& f, void* storage, Args&&... args) noexcept(noexcept(f(std::declval(), args...))) { if (index < $(max_expanded)) { return VariantCastAndCallImpl( brigand::list<$type_list(max_expanded - 1)>{}, index, f, storage, args...); } else { return VariantCastAndCallImpl( brigand::list{}, index - $(max_expanded), f, storage, args...); } } } } } } // vtkm::VTK_M_NAMESPACE::internal::detail