Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::pair

      From cppreference.com
      <cpp‎ |utility
       
       
      Utilities library
       
       
      Defined in header<utility>
      template<

         class T1,
         class T2

      >struct pair;

      std::pair is a class template that provides a way to store two heterogeneous objects as a single unit. A pair is a specific case of astd::tuple with two elements.

      If neitherT1 norT2 is a possibly cv-qualified class type with non-trivial destructor, or array thereof, the destructor ofpair is trivial.

      Contents

      [edit]Template parameters

      T1, T2 - the types of the elements that the pair stores.

      [edit]Member types

      Member type Definition
      first_typeT1
      second_typeT2

      [edit]Member objects

      Member name Type
      firstT1
      secondT2

      [edit]Member functions

      constructs newpair
      (public member function)[edit]
      assigns the contents
      (public member function)[edit]
      (C++11)
      swaps the contents
      (public member function)[edit]

      [edit]Non-member functions

      creates apair object of type, determined by the argument types
      (function template)[edit]
      (removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
      lexicographically compares the values in thepair
      (function template)[edit]
      specializes thestd::swap algorithm
      (function template)[edit]
      accesses an element of apair
      (function template)[edit]

      [edit]Helper classes

      obtains the size of apair
      (class template specialization)[edit]
      obtains the type of the elements ofpair
      (class template specialization)[edit]
      determines the common reference type of twopairs
      (class template specialization)[edit]
      determines the common type of twopairs
      (class template specialization)[edit]
      formatting support forpair
      (class template specialization)[edit]

      [edit]Helper specializations

      template<class T,class U>

      constexprbool enable_nonlocking_formatter_optimization<std::pair<T, U>>=
          enable_nonlocking_formatter_optimization<T>&&

          enable_nonlocking_formatter_optimization<U>;
      (since C++23)

      This specialization ofstd::enable_nonlocking_formatter_optimization enables efficient implementation ofstd::print andstd::println for printing apair object when bothT andU enable it.

      [edit]Deduction guides(since C++17)

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 2796C++98triviality of the destructor ofpair was unspecifiedspecified

      [edit]See also

      (C++11)
      implements fixed size container, which holds elements of possibly different types
      (class template)[edit]
      (C++11)
      creates atuple of lvalue references or unpacks a tuple into individual objects
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/pair&oldid=181396"

      [8]ページ先頭

      ©2009-2025 Movatter.jp