STLUtils.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-17
  6. * Changed: 2022-05-09
  7. *
  8. * */
  9. #ifndef LS_STD_STL_UTILS_HPP
  10. #define LS_STD_STL_UTILS_HPP
  11. #include <algorithm>
  12. #include <list>
  13. namespace ls
  14. {
  15. namespace std
  16. {
  17. namespace core
  18. {
  19. class STLUtils
  20. {
  21. public:
  22. STLUtils() = default;
  23. ~STLUtils() = default;
  24. template<class container, class dataType>
  25. static bool contains(container _container, const dataType &_value)
  26. {
  27. return ::std::find(_container.begin(), _container.end(), _value) != _container.end();
  28. }
  29. template<class dataType>
  30. static dataType getListElementAt(const ::std::list<dataType> &_list, size_t _index)
  31. {
  32. dataType value{};
  33. size_t counter{};
  34. if (_index < _list.size())
  35. {
  36. for (const auto &_value: _list)
  37. {
  38. if (counter == _index)
  39. {
  40. value = _value;
  41. break;
  42. }
  43. counter++;
  44. }
  45. }
  46. return value;
  47. }
  48. };
  49. }
  50. }
  51. }
  52. #endif