// SPDX-License-Identifier: BSD-3-Clause
#ifndef SUBSTRATE_PROMOTION_HELPERS
#define SUBSTRATE_PROMOTION_HELPERS

#include <cstdint>
#include <type_traits>
#include <substrate/internal/types>

namespace substrate
{
	template<typename T, bool = std::is_unsigned<T>::value> struct promoted_type;
	template<typename T> struct promoted_type<T, true> { using type = uint32_t; };
	template<typename T> struct promoted_type<T, false> { using type = int32_t; };
	template<> struct promoted_type<uint64_t, true> { using type = uint64_t; };
	template<> struct promoted_type<int64_t, false> { using type = int64_t; };
	template<> struct promoted_type<size_t, !std::is_same<uint64_t, size_t>::value> { using type = size_t; };
	template<> struct promoted_type<ssize_t, std::is_same<int64_t, ssize_t>::value> { using type = ssize_t; };

	template<typename T> using promoted_type_t = typename promoted_type<T>::type;
} // namespace substrate

#endif /*SUBSTRATE_PROMOTION_HELPERS*/
/* vim: set ft=cpp ts=4 sw=4 noexpandtab: */
