STLUtils.hpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-17
  6. * Changed: 2022-07-02
  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::std::core
  14. {
  15. class STLUtils
  16. {
  17. public:
  18. STLUtils() = default;
  19. ~STLUtils() = default;
  20. template<class container, class dataType>
  21. static bool contains(container _container, const dataType &_value)
  22. {
  23. return ::std::find(_container.begin(), _container.end(), _value) != _container.end();
  24. }
  25. template<class dataType>
  26. static dataType getListElementAt(const ::std::list<dataType> &_list, size_t _index)
  27. {
  28. dataType value{};
  29. size_t counter{};
  30. if (_index < _list.size())
  31. {
  32. for (const auto &_value: _list)
  33. {
  34. if (counter == _index)
  35. {
  36. value = _value;
  37. break;
  38. }
  39. counter++;
  40. }
  41. }
  42. return value;
  43. }
  44. };
  45. }
  46. #endif