IteratorDemo.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "IteratorDemo.h"
  2. #include "RingQueue.hpp"
  3. struct User_t
  4. {
  5. int id;
  6. std::string name;
  7. };
  8. void testRingQueueManualMutex()
  9. {
  10. RingQueueManualMutex<User_t> queue(5);
  11. queue.push({1, "Alice"});
  12. queue.push({2, "Bob"});
  13. queue.push({3, "Charlie"});
  14. queue.push({4, "Diana"});
  15. queue.push({5, "Ethan"});
  16. for(auto it : queue)
  17. {
  18. SPDLOG_INFO("Value: id={}, name={}", it.id, it.name);
  19. }
  20. SPDLOG_INFO("---------------------------------------------");
  21. SPDLOG_INFO("倒叙遍历: ");
  22. auto it = queue.end();
  23. --it;
  24. for(; it != queue.begin(); it--)
  25. {
  26. SPDLOG_INFO("Value: id={}, name={}", it->id, it->name);
  27. }
  28. SPDLOG_INFO("Value: id={}, name={}", it->id, it->name);
  29. SPDLOG_INFO("RingQueueManualMutex 测试完成");
  30. }
  31. void testRingQueue()
  32. {
  33. RingQueue<User_t> queue;
  34. queue.push({1, "Alice"});
  35. queue.push({2, "Bob"});
  36. queue.push({3, "Charlie"});
  37. // for(const auto& user : queue)
  38. // {
  39. // SPDLOG_INFO("User ID: {}, Name: {}", user.id, user.name);
  40. // }
  41. }