begin.pass.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. // <array>
  9. // iterator begin();
  10. #include <array>
  11. #include <cassert>
  12. #include "test_macros.h"
  13. // std::array is explicitly allowed to be initialized with A a = { init-list };.
  14. // Disable the missing braces warning for this reason.
  15. #include "disable_missing_braces_warning.h"
  16. struct NoDefault {
  17. NoDefault(int) {}
  18. };
  19. int main(int, char**)
  20. {
  21. {
  22. typedef double T;
  23. typedef std::array<T, 3> C;
  24. C c = {1, 2, 3.5};
  25. C::iterator i;
  26. i = c.begin();
  27. assert(*i == 1);
  28. assert(&*i == c.data());
  29. *i = 5.5;
  30. assert(c[0] == 5.5);
  31. }
  32. {
  33. typedef NoDefault T;
  34. typedef std::array<T, 0> C;
  35. C c = {};
  36. C::iterator ib, ie;
  37. ib = c.begin();
  38. ie = c.end();
  39. assert(ib == ie);
  40. LIBCPP_ASSERT(ib != nullptr);
  41. LIBCPP_ASSERT(ie != nullptr);
  42. }
  43. return 0;
  44. }