fill.pass.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. // void fill(const T& u);
  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. c.fill(5.5);
  23. assert(c.size() == 3);
  24. assert(c[0] == 5.5);
  25. assert(c[1] == 5.5);
  26. assert(c[2] == 5.5);
  27. }
  28. {
  29. typedef double T;
  30. typedef std::array<T, 0> C;
  31. C c = {};
  32. c.fill(5.5);
  33. assert(c.size() == 0);
  34. }
  35. return 0;
  36. }