PMT Renovated main
Partition Manager Tool is a fast, reliable, and feature-rich CLI application for Android devices that enables advanced partition operations such as backup, flashing, erasing, information retrieval, and more.
Loading...
Searching...
No Matches
Helper::IsCloser Concept Reference

Checks if the input class can close the needed thing, either as a operator() or using the close() function. More...

#include <management.hpp>

Concept definition

template<typename Class, typename Type>
concept Helper::IsCloser = requires(Class c, Type t) {
{ c(t) } -> std::same_as<void>;
} || requires(Class c, Type t) {
{ c.close(t) } -> std::same_as<void>;
}
Checks if the input class can close the needed thing, either as a operator() or using the close() fun...
Definition management.hpp:314
T forward(T... args)

Detailed Description

Checks if the input class can close the needed thing, either as a operator() or using the close() function.

// A example valid class structure.
class CloserWithFunction {
template <typename>
static constexpr bool always_false = false;
public:
template <typename T>
void close(T &var) const noexcept {
if constexpr (std::is_same_v<std::decay_t<T>, int>) {
if (static_cast<int>(var) >= 0) ::close(static_cast<int>(var));
} else if constexpr (std::is_same_v<std::decay_t<T>, FILE*>) {
if (var != nullptr) fclose(var);
} else if constexpr (std::is_same_v<std::decay_t<T>, DIR*>) {
if (var != nullptr) closedir(var);
} else {
static_assert(always_false<T>, "Unsupported input type. Closer is only supports int, FILE* and DIR*");
}
}
};
// --- OR --- //
class CloserWithOperator {
template <typename>
static constexpr bool always_false = false;
public:
template <typename T>
void operator()(T &var) const noexcept {
if constexpr (std::is_same_v<std::decay_t<T>, int>) {
if (static_cast<int>(var) >= 0) ::close(static_cast<int>(var));
} else if constexpr (std::is_same_v<std::decay_t<T>, FILE*>) {
if (var != nullptr) fclose(var);
} else if constexpr (std::is_same_v<std::decay_t<T>, DIR*>) {
if (var != nullptr) closedir(var);
} else {
static_assert(always_false<T>, "Unsupported input type. Closer is only supports int, FILE* and DIR*");
}
}
};
// To see how this concept is used, check out Helper::BasicUniqueFD or Helper::BasicUniqueFP.
T fclose(T... args)
Template Parameters
ClassClass.
TypeNeeded type.
See also
Helper::BasicUniqueFD
Helper::BasicUniqueFP
Note
The return type of the desired close() function/operator() must be void.