Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::forward_as_tuple

      From cppreference.com
      <cpp‎ |utility‎ |tuple
       
       
      Utilities library
       
       
      Defined in header<tuple>
      template<class...Types>
      std::tuple<Types&&...> forward_as_tuple( Types&&...args)noexcept;
      (since C++11)
      (constexpr since C++14)

      Constructs a tuple of references to the arguments inargs suitable for forwarding as an argument to a function. The tuple has rvalue reference data members when rvalues are used as arguments, and otherwise has lvalue reference data members.

      Contents

      [edit]Parameters

      args - zero or more arguments to construct the tuple from

      [edit]Return value

      Astd::tuple object created as if bystd::tuple<Types&&...>(std::forward<Types>(args)...)

      [edit]Notes

      If the arguments are temporaries,forward_as_tuple does not extend their lifetime; they have to be used before the end of the full expression.

      [edit]Example

      Run this code
      #include <iostream>#include <map>#include <string>#include <tuple> int main(){std::map<int,std::string> m;     m.emplace(std::piecewise_construct,              std::forward_as_tuple(6),              std::forward_as_tuple(9,'g'));std::cout<<"m[6] = "<< m[6]<<'\n'; // The following is an error: it produces a// std::tuple<int&&, char&&> holding two dangling references.//// auto t = std::forward_as_tuple(20, 'a');// m.emplace(std::piecewise_construct, std::forward_as_tuple(10), t);}

      Output:

      m[6] = ggggggggg

      [edit]See also

      (C++11)
      creates atuple object of the type defined by the argument types
      (function template)[edit]
      (C++11)
      creates atuple of lvalue references or unpacks a tuple into individual objects
      (function template)[edit]
      (C++11)
      creates atuple by concatenating any number of tuples
      (function template)[edit]
      (C++17)
      calls a function with a tuple of arguments
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/tuple/forward_as_tuple&oldid=177795"

      [8]ページ先頭

      ©2009-2025 Movatter.jp