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
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace cpp17 {
|
||||
|
||||
[[nodiscard]] auto safe_divide(int lhs, int rhs) -> std::optional<double>;
|
||||
[[nodiscard]] auto find_user(const std::vector<std::string>& users, const std::string& name)
|
||||
-> std::optional<std::size_t>;
|
||||
[[nodiscard]] auto first_positive(const std::vector<int>& data) -> std::optional<int>;
|
||||
|
||||
} // namespace cpp17
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
namespace cpp17 {
|
||||
|
||||
[[nodiscard]] auto minmax_pair(const std::vector<int>& data) -> std::pair<int, int>;
|
||||
[[nodiscard]] auto split_key_value(const std::string& text) -> std::pair<std::string, std::string>;
|
||||
[[nodiscard]] auto first_pair(const std::map<std::string, int>& scores)
|
||||
-> std::tuple<std::string, int, bool>;
|
||||
|
||||
} // namespace cpp17
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
namespace cpp17 {
|
||||
|
||||
using Value = std::variant<int, double, std::string>;
|
||||
|
||||
[[nodiscard]] auto variant_to_string(const Value& value) -> std::string;
|
||||
[[nodiscard]] auto sum_numeric_variants(const std::vector<Value>& values) -> double;
|
||||
[[nodiscard]] auto is_string(const Value& value) -> bool;
|
||||
|
||||
} // namespace cpp17
|
||||
Reference in New Issue
Block a user