Skip to content

Commit

Permalink
Add more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarfovich committed Jul 31, 2024
1 parent 7f8fe5b commit 7709c46
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
15 changes: 14 additions & 1 deletion HW4/include/print_ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename T, std::enable_if_t<std::is_integral_v<T>, bool> = false>
void print_ip(const T& v)
{
Expand All @@ -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<typename T, std::enable_if_t<std::is_same_v<std::string, T>, 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<typename T, std::enable_if_t<(sizeof(typename T::const_iterator) > 0) && !std::is_same_v<std::string, T>, bool> = false>
void print_ip(const T& c)
{
Expand Down Expand Up @@ -73,6 +82,10 @@ void print_tuple(const std::tuple<Ts...>& 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<typename... Ts, std::enable_if_t<(sizeof...(Ts) > 0), bool> = false>
void print_ip(const std::tuple<Ts...>& tuple)
{
Expand Down
11 changes: 6 additions & 5 deletions HW4/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> { 100, 200, 300, 400 }); // 100.200.300.400
print_ip_with_endl(std::list<short> { 400, 300, 200, 100 }); // 400.300.200.100
print_ip_with_endl(std::list<short> { 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;
}

0 comments on commit 7709c46

Please sign in to comment.