size.pass.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. // template <class T, size_t N> constexpr size_type array<T,N>::size();
  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. int main(int, char**)
  17. {
  18. {
  19. typedef double T;
  20. typedef std::array<T, 3> C;
  21. C c = {1, 2, 3.5};
  22. assert(c.size() == 3);
  23. assert(c.max_size() == 3);
  24. assert(!c.empty());
  25. }
  26. {
  27. typedef double T;
  28. typedef std::array<T, 0> C;
  29. C c = {};
  30. assert(c.size() == 0);
  31. assert(c.max_size() == 0);
  32. assert(c.empty());
  33. }
  34. #if TEST_STD_VER >= 11
  35. {
  36. typedef double T;
  37. typedef std::array<T, 3> C;
  38. constexpr C c = {1, 2, 3.5};
  39. static_assert(c.size() == 3, "");
  40. static_assert(c.max_size() == 3, "");
  41. static_assert(!c.empty(), "");
  42. }
  43. {
  44. typedef double T;
  45. typedef std::array<T, 0> C;
  46. constexpr C c = {};
  47. static_assert(c.size() == 0, "");
  48. static_assert(c.max_size() == 0, "");
  49. static_assert(c.empty(), "");
  50. }
  51. #endif
  52. return 0;
  53. }