12 #ifndef PLSSVM_DETAIL_UTILITY_HPP_
13 #define PLSSVM_DETAIL_UTILITY_HPP_
24 #include <type_traits>
37 __builtin_unreachable();
38 #elif defined(_MSC_VER)
50 template <std::size_t I,
typename... Types>
51 [[nodiscard]] constexpr decltype(
auto)
get(Types &&...args) noexcept {
52 static_assert(I <
sizeof...(Types),
"Out-of-bounce access!: too few elements in parameter pack");
53 return std::get<I>(std::forward_as_tuple(args...));
62 template <
typename Enum>
63 [[nodiscard]] constexpr std::underlying_type_t<Enum>
to_underlying(
const Enum e) noexcept {
64 static_assert(std::is_enum_v<Enum>,
"e must be an enumeration type!");
65 return static_cast<std::underlying_type_t<Enum>
>(e);
74 template <
typename Enum>
76 static_assert(std::is_enum_v<Enum>,
"e must be an enumeration type!");
88 template <
typename Container,
typename Pred, PLSSVM_REQUIRES(is_container_v<Container>)>
89 inline typename Container::size_type
erase_if(Container &c, Pred pred) {
90 if constexpr (is_vector_v<Container>) {
92 auto iter = std::remove_if(c.begin(), c.end(), pred);
93 auto dist = std::distance(iter, c.end());
94 c.erase(iter, c.end());
98 auto old_size = c.size();
99 for (
auto i = c.begin(), last = c.end(); i != last;) {
106 return old_size - c.size();
118 template <
typename Container,
typename T, PLSSVM_REQUIRES(is_container_v<Container>)>
119 [[nodiscard]]
inline bool contains(
const Container &c,
const T &val) {
120 if constexpr (is_sequence_container_v<Container>) {
122 return std::find(c.cbegin(), c.cend(), val) != c.cend();
125 return c.count(val) > 0;
This class encapsulates a value that may be a default value or not.
Definition: default_value.hpp:62
Implements a class used to be able to distinguish between the default value of a variable and an assi...
Namespace containing implementation details. Should not directly be used by users.
Definition: csvm.hpp:27
Container::size_type erase_if(Container &c, Pred pred)
Implements an erase_if function for different containers according to https://en.cppreference....
Definition: utility.hpp:89
std::string current_date_time()
Return the current date time in the format "YYYY-MM-DD hh:mm:ss".
void unreachable()
Invokes undefined behavior. Used to mark code paths that may never be reachable.
Definition: utility.hpp:32
bool contains(std::string_view str, std::string_view sv) noexcept
Checks if the string str contains the string sv.
constexpr decltype(auto) get(Types &&...args) noexcept
Get the I-th element of the parameter pack args at compile-time.
Definition: utility.hpp:51
constexpr std::underlying_type_t< Enum > to_underlying(const Enum e) noexcept
Converts an enumeration to its underlying type.
Definition: utility.hpp:63
Defines some generic type traits used in the PLSSVM library.