diff --git a/HW4/include/print_ip.h b/HW4/include/print_ip.h index fd288e9..bd05984 100644 --- a/HW4/include/print_ip.h +++ b/HW4/include/print_ip.h @@ -8,7 +8,7 @@ /// Function print_ip prints a single value. /// /// This is an overloaded function that prints value of integral types. -/// @param v Integer value to print +/// @param v Integer value to print. template, bool> = false> void print_ip(const T& v) { @@ -24,12 +24,21 @@ void print_ip(const T& v) } } +/// Function print_ip prints a single value. +/// +/// This is an overloaded function that prints value of std::string. +/// @param str String to print. template, bool> = false> void print_ip(const T& str) { std::cout << str; } +/// Function print_ip prints a single value. +/// +/// This is an overloaded function that prints value stored in container that supports one-directional const iterator +/// (for example, std::list and std::vector). +/// @param c Container to print. template 0) && !std::is_same_v, bool> = false> void print_ip(const T& c) { @@ -73,6 +82,10 @@ void print_tuple(const std::tuple& tuple) } // namespace details +/// Function print_ip prints a single value. +/// +/// This is an overloaded function that prints value stored in tuple. Note: tuple has to has elements of the single type. +/// @param tuple Tuple to print. template 0), bool> = false> void print_ip(const std::tuple& tuple) { diff --git a/HW4/src/main.cpp b/HW4/src/main.cpp index 43dc8f9..81cdaaa 100644 --- a/HW4/src/main.cpp +++ b/HW4/src/main.cpp @@ -20,18 +20,19 @@ void print_ip_with_endl(const T& v) std::cout << std::endl; } -int main() { +int main() +{ print_ip_with_endl(int8_t { -1 }); // 255 print_ip_with_endl(int16_t { 0 }); // 0.0 print_ip_with_endl(int32_t { 2130706433 }); // 127.0.0.1 print_ip_with_endl(int64_t { 8875824491850138409 }); // 123.45.67.89.101.112.131.41 - print_ip_with_endl(std::string {"Hello, World !"}); // Hello, World! + print_ip_with_endl(std::string { "Hello, World !" }); // Hello, World! print_ip_with_endl(std::vector { 100, 200, 300, 400 }); // 100.200.300.400 - print_ip_with_endl(std::list { 400, 300, 200, 100 }); // 400.300.200.100 + print_ip_with_endl(std::list { 400, 300, 200, 100 }); // 400.300.200.100 print_ip_with_endl(std::make_tuple(123, 456, 789, 0)); // 123.456.789.0 - //std::tuple t2 { 9, true }; - //print_ip(t2); // Fail to compile. + // std::tuple t2 { 9, true }; + // print_ip(t2); // Fail to compile. return 0; }