Initial Course
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
namespace cpp17 {
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] constexpr auto type_name() -> const char* {
|
||||
if constexpr (std::is_integral_v<T>) {
|
||||
return "integral";
|
||||
} else if constexpr (std::is_floating_point_v<T>) {
|
||||
return "floating";
|
||||
} else {
|
||||
return "other";
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Container>
|
||||
[[nodiscard]] auto element_count(const Container& container) -> std::size_t {
|
||||
if constexpr (std::is_member_function_pointer_v<decltype(&Container::size)>) {
|
||||
return container.size();
|
||||
} else {
|
||||
std::size_t count = 0;
|
||||
for ([[maybe_unused]] const auto& item : container) {
|
||||
++count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] auto stringify_ints(const std::vector<int>& data) -> std::string;
|
||||
|
||||
} // namespace cpp17
|
||||
Reference in New Issue
Block a user