initializer_list.pass.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. // Construct with initizializer list
  10. #include <array>
  11. #include <cassert>
  12. // std::array is explicitly allowed to be initialized with A a = { init-list };.
  13. // Disable the missing braces warning for this reason.
  14. #include "test_macros.h"
  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[0] == 1);
  24. assert(c[1] == 2);
  25. assert(c[2] == 3.5);
  26. }
  27. {
  28. typedef double T;
  29. typedef std::array<T, 0> C;
  30. C c = {};
  31. assert(c.size() == 0);
  32. }
  33. {
  34. typedef double T;
  35. typedef std::array<T, 3> C;
  36. C c = {1};
  37. assert(c.size() == 3.0);
  38. assert(c[0] == 1);
  39. }
  40. {
  41. typedef int T;
  42. typedef std::array<T, 1> C;
  43. C c = {};
  44. assert(c.size() == 1);
  45. }
  46. return 0;
  47. }