/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* PrintNb.hpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/08 14:30:07 by adjoly #+# #+# */ /* Updated: 2025/04/09 10:32:48 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #pragma once #include #include #include #include template void _printFloat(T nb) { std::cout << "float: " << static_cast(nb) << "f" << std::endl; } template void _printInt(T nb) { std::cout << "int: "; if (nb < std::numeric_limits::min() || nb > std::numeric_limits::max()) std::cout << "impossible" << std::endl; else std::cout << static_cast(nb) << std::endl; } template void _printChar(T nb) { std::cout << "char: "; if (nb < std::numeric_limits::min() || nb > std::numeric_limits::max()) std::cout << "impossible" << std::endl; else if (!isprint(nb)) std::cout << "Non displayable" << std::endl; else std::cout << "'" << static_cast(nb) << "'" << std::endl; } template void _printDouble(T nb) { std::cout << "double: " << static_cast(nb) << std::endl; } template T _ConvertTo(const std::string &str) { std::stringstream ss(str); T ret; ss >> ret; return ret; } template void _Convert(const std::string &str) { T nb = _ConvertTo(str); _printChar(nb); _printInt(nb); _printFloat(nb); _printDouble(nb); }