2022-02-27 13:48:21 +01:00
|
|
|
#ifndef GENERALUTILITY_GENERALUTILITY_H
|
|
|
|
#define GENERALUTILITY_GENERALUTILITY_H
|
|
|
|
|
2022-02-27 14:05:51 +01:00
|
|
|
#include <algorithm>
|
|
|
|
#include <utility>
|
|
|
|
|
2022-02-27 13:48:21 +01:00
|
|
|
class GeneralUtility {
|
|
|
|
public:
|
2022-02-27 14:05:51 +01:00
|
|
|
template <typename T_Type, class T_Container>
|
|
|
|
static int Ord(const T_Type& item, const T_Container& set);
|
2022-02-27 13:48:21 +01:00
|
|
|
private:
|
2022-02-27 14:32:09 +01:00
|
|
|
// No instantiation! >:(
|
2022-02-27 13:48:21 +01:00
|
|
|
GeneralUtility();
|
|
|
|
};
|
|
|
|
|
2022-02-27 14:05:51 +01:00
|
|
|
template<typename T_Type, class T_Container>
|
2022-02-27 14:32:09 +01:00
|
|
|
int GeneralUtility::Ord(const T_Type& item, const T_Container& set) {
|
2022-02-27 14:05:51 +01:00
|
|
|
const auto result =
|
2022-02-27 14:32:09 +01:00
|
|
|
std::find_if(set.begin(), set.end(), [item](const T_Type& c) -> bool {
|
2022-02-27 14:05:51 +01:00
|
|
|
return c == item;
|
|
|
|
});
|
|
|
|
|
|
|
|
// No item found
|
|
|
|
if (result == set.end())
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return result - set.begin();
|
|
|
|
}
|
|
|
|
|
2022-02-27 13:48:21 +01:00
|
|
|
#endif //GENERALUTILITY_GENERALUTILITY_H
|