/* * Copyright 2008-2012 NVIDIA Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include namespace thrust { namespace detail { namespace minimum_type_detail { // // Returns the minimum type or is empty // if T1 and T2 are unrelated. // template struct minimum_type_impl {}; template struct minimum_type_impl { typedef T2 type; }; // end minimum_type_impl template struct minimum_type_impl { typedef T1 type; }; // end minimum_type_impl template struct minimum_type_impl { typedef T1 type; }; // end minimum_type_impl template struct primitive_minimum_type : minimum_type_detail::minimum_type_impl< T1, T2, ::thrust::detail::is_convertible::value, ::thrust::detail::is_convertible::value > { }; // end primitive_minimum_type // because some types are not convertible (even to themselves) // specialize primitive_minimum_type for when both types are identical template struct primitive_minimum_type { typedef T type; }; // end primitive_minimum_type // XXX this belongs somewhere more general struct any_conversion { template operator T (void); }; } // end minimum_type_detail template struct minimum_type; // base case template struct minimum_type : minimum_type_detail::primitive_minimum_type {}; template struct lazy_minimum_type : minimum_type< typename T1::type, typename T2::type > {}; // carefully avoid referring to a nested ::type which may not exist template struct minimum_type : lazy_minimum_type< lazy_minimum_type< lazy_minimum_type< minimum_type< T1,T2 >, minimum_type< T3,T4 > >, lazy_minimum_type< minimum_type< T5,T6 >, minimum_type< T7,T8 > > >, lazy_minimum_type< lazy_minimum_type< minimum_type< T9,T10 >, minimum_type< T11,T12 > >, lazy_minimum_type< minimum_type< T13,T14 >, minimum_type< T15,T16 > > > > {}; } // end detail } // end thrust