/* * This file is part of libgim. * * libgim is free software: you can redistribute it and/or modify it under the * terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * libgim is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with libgim. If not, see . * * 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