get_const.fail.cpp 1.1 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. // <tuple>
  9. // template <class... Types> class tuple;
  10. // template <size_t I, class... Types>
  11. // typename tuple_element<I, tuple<Types...> >::type const&
  12. // get(const tuple<Types...>& t);
  13. // UNSUPPORTED: c++98, c++03
  14. #include <tuple>
  15. #include <string>
  16. #include <cassert>
  17. int main(int, char**)
  18. {
  19. {
  20. typedef std::tuple<double&, std::string, int> T;
  21. double d = 1.5;
  22. const T t(d, "high", 5);
  23. assert(std::get<0>(t) == 1.5);
  24. assert(std::get<1>(t) == "high");
  25. assert(std::get<2>(t) == 5);
  26. std::get<0>(t) = 2.5;
  27. assert(std::get<0>(t) == 2.5);
  28. assert(std::get<1>(t) == "high");
  29. assert(std::get<2>(t) == 5);
  30. assert(d == 2.5);
  31. std::get<1>(t) = "four";
  32. }
  33. return 0;
  34. }