containers.h
49 lines
| 1.5 KiB
| text/x-c
|
CLexer
r0 | #ifndef CONTAINERS_H | |||
#define CONTAINERS_H | ||||
r53 | #include "cpp_utils.h" | |||
r0 | ||||
r53 | #include <algorithm> | |||
#include <map> | ||||
#include <vector> | ||||
r0 | ||||
r53 | namespace SciQLop::containers | |||
r0 | { | |||
r53 | template<class T1, class T2> | |||
auto contains(const T1& container, const T2& value) | ||||
-> decltype(container.front(), std::end(container), true) | ||||
{ | ||||
return std::find(std::cbegin(container), std::cend(container), value) != | ||||
std::cend(container); | ||||
} | ||||
r0 | ||||
r53 | template<class T1, class T2> | |||
auto contains(const T1& container, const T2& value) | ||||
-> decltype(container.find(value), std::cend(container), true) | ||||
{ | ||||
return container.find(value) != std::cend(container); | ||||
} | ||||
r0 | ||||
r54 | template<class T1, class T2> | |||
auto index_of(const T1& container, const T2& value) | ||||
-> decltype(container.front() == value, 0) | ||||
{ | ||||
return std::distance( | ||||
std::cbegin(container), | ||||
std::find(std::cbegin(container), std::cend(container), value)); | ||||
} | ||||
template<class T1, class T2> | ||||
auto index_of(const T1& container, const T2& value) | ||||
-> decltype(container.front().get(), std::is_pointer<T2>::value, 0) | ||||
{ | ||||
return std::distance(std::cbegin(container), | ||||
std::find_if(std::cbegin(container), | ||||
std::cend(container), | ||||
[value](const auto& item) { | ||||
return value == item.get(); | ||||
})); | ||||
} | ||||
r53 | } // namespace SciQLop::containers | |||
r0 | ||||
#endif // CONTAINERS_H | ||||