From 2364bff11fe115c34bcdc46778371af5172718e8 Mon Sep 17 00:00:00 2001 From: BlackMark Date: Sun, 28 Jul 2019 10:49:14 +0200 Subject: [PATCH] Implemented automatic type deducation depending on data bits --- settings.hpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/settings.hpp b/settings.hpp index d646e57..a6575fb 100644 --- a/settings.hpp +++ b/settings.hpp @@ -29,6 +29,20 @@ enum class Parity { EVEN, }; +namespace detail { + +template +struct choose_data_size { + using type = uint8_t; +}; + +template <> +struct choose_data_size { + using type = uint16_t; +}; + +} // namespace detail + template class settings { @@ -37,7 +51,7 @@ class settings { static constexpr auto DATA_BITS = dataBits; static constexpr auto PARITY = parity; static constexpr auto STOP_BITS = stopBits; - using data_t = uint8_t; + using data_t = typename detail::choose_data_size::type; }; } // namespace uart