/* * 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. * * Copyright 2012 Danny Robson */ #ifndef __UTIL_TYPES_TRAITS_HPP #define __UTIL_TYPES_TRAITS_HPP #include #include //----------------------------------------------------------------------------- template struct is_dereferencable : std::false_type { }; template struct is_dereferencable : std::true_type { }; template struct is_dereferencable> : std::true_type { }; template struct is_dereferencable> : std::true_type { }; template struct is_dereferencable> : std::true_type { }; template struct is_dereferencable> : std::true_type { }; template struct dereferenced_type { typedef typename std::enable_if< std::is_pointer::value, std::remove_pointer >::type type; }; //----------------------------------------------------------------------------- template struct dereferenced_type> { typedef T type; }; template struct dereferenced_type> { typedef T type; }; template struct dereferenced_type> { typedef T type; }; template struct dereferenced_type> { typedef T type; }; ///---------------------------------------------------------------------------- /// find the unsigned version of a type if one exists template struct try_unsigned { typedef typename std::make_unsigned::type type; }; template <> struct try_unsigned { typedef double type; }; template <> struct try_unsigned { typedef float type; }; ///---------------------------------------------------------------------------- /// find the signed version of a type if one exists template struct try_signed { typedef typename std::make_signed::type type; }; template <> struct try_signed { typedef double type; }; template <> struct try_signed { typedef float type; }; ///---------------------------------------------------------------------------- /// checks if a type can be converted in all cases without modification template struct is_lossless_cast : std::enable_if< std::is_integral::value && std::is_integral::value && std::is_signed::value == std::is_signed::value && sizeof (T) <= sizeof (U), std::true_type >::value { }; //----------------------------------------------------------------------------- template struct func_traits : public func_traits { }; template struct func_traits { typedef R return_type; }; template struct func_traits { typedef R return_type; }; #endif