STLUtils.hpp 1.1 KB

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