tie.pass.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <tuple>
  10. // template <class... Types> class tuple;
  11. // template<class... Types>
  12. // tuple<Types&...> tie(Types&... t);
  13. // UNSUPPORTED: c++98, c++03
  14. #include <tuple>
  15. #include <string>
  16. #include <cassert>
  17. #include "test_macros.h"
  18. int main()
  19. {
  20. {
  21. int i = 0;
  22. std::string s;
  23. std::tie(i, std::ignore, s) = std::make_tuple(42, 3.14, "C++");
  24. assert(i == 42);
  25. assert(s == "C++");
  26. }
  27. {
  28. static constexpr int i = 42;
  29. static constexpr double f = 1.1;
  30. constexpr std::tuple<const int &, const double &> t = std::tie(i, f);
  31. static_assert ( std::get<0>(t) == 42, "" );
  32. static_assert ( std::get<1>(t) == 1.1, "" );
  33. }
  34. }