iterator.pass.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // <iterator>
  9. // template<class Iter>
  10. // struct iterator_traits
  11. // {
  12. // typedef typename Iter::difference_type difference_type;
  13. // typedef typename Iter::value_type value_type;
  14. // typedef typename Iter::pointer pointer;
  15. // typedef typename Iter::reference reference;
  16. // typedef typename Iter::iterator_category iterator_category;
  17. // };
  18. #include <iterator>
  19. #include <type_traits>
  20. #include "test_macros.h"
  21. struct A {};
  22. struct test_iterator
  23. {
  24. typedef int difference_type;
  25. typedef A value_type;
  26. typedef A* pointer;
  27. typedef A& reference;
  28. typedef std::forward_iterator_tag iterator_category;
  29. };
  30. int main(int, char**)
  31. {
  32. typedef std::iterator_traits<test_iterator> It;
  33. static_assert((std::is_same<It::difference_type, int>::value), "");
  34. static_assert((std::is_same<It::value_type, A>::value), "");
  35. static_assert((std::is_same<It::pointer, A*>::value), "");
  36. static_assert((std::is_same<It::reference, A&>::value), "");
  37. static_assert((std::is_same<It::iterator_category, std::forward_iterator_tag>::value), "");
  38. return 0;
  39. }