Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::unordered_set<Key,Hash,KeyEqual,Allocator>::unordered_set

      From cppreference.com
      <cpp‎ |container‎ |unordered set

      [edit template]
       
       
       
      std::unordered_set
      Member types
      Member functions
      Non-member functions
      Deduction guides(C++17)
       
      (1)
      unordered_set()
         : unordered_set(size_type(/* unspecified */)){}
      (since C++11)
      (until C++20)
      unordered_set();
      (since C++20)
      explicit unordered_set( size_type bucket_count,

                             const Hash& hash= Hash(),
                             const key_equal& equal= key_equal(),

                             const Allocator& alloc= Allocator());
      (2)(since C++11)
      unordered_set( size_type bucket_count,

                     const Allocator& alloc)

         : unordered_set(bucket_count, Hash(), key_equal(), alloc){}
      (3)(since C++14)
      unordered_set( size_type bucket_count,

                     const Hash& hash,
                     const Allocator& alloc)

         : unordered_set(bucket_count, hash, key_equal(), alloc){}
      (4)(since C++14)
      explicit unordered_set(const Allocator& alloc);
      (5)(since C++11)
      template<class InputIt>

      unordered_set( InputIt first, InputIt last,
                     size_type bucket_count=/* unspecified */,
                     const Hash& hash= Hash(),
                     const key_equal& equal= key_equal(),

                     const Allocator& alloc= Allocator());
      (6)(since C++11)
      template<class InputIt>

      unordered_set( InputIt first, InputIt last,
                     size_type bucket_count,
                     const Allocator& alloc)
         : unordered_set(first, last,

                          bucket_count, Hash(), key_equal(), alloc){}
      (7)(since C++14)
      template<class InputIt>

      unordered_set( InputIt first, InputIt last,
                     size_type bucket_count,
                     const Hash& hash,
                     const Allocator& alloc)
         : unordered_set(first, last,

                          bucket_count, hash, key_equal(), alloc){}
      (8)(since C++14)
      unordered_set(const unordered_set& other);
      (9)(since C++11)
      unordered_set(const unordered_set& other,const Allocator& alloc);
      (10)(since C++11)
      unordered_set( unordered_set&& other);
      (11)(since C++11)
      unordered_set( unordered_set&& other,const Allocator& alloc);
      (12)(since C++11)
      unordered_set(std::initializer_list<value_type> init,

                     size_type bucket_count=/* unspecified */,
                     const Hash& hash= Hash(),
                     const key_equal& equal= key_equal(),

                     const Allocator& alloc= Allocator());
      (13)(since C++11)
      unordered_set(std::initializer_list<value_type> init,

                     size_type bucket_count,
                     const Allocator& alloc)
         : unordered_set(init, bucket_count,

                          Hash(), key_equal(), alloc){}
      (14)(since C++14)
      unordered_set(std::initializer_list<value_type> init,

                     size_type bucket_count,
                     const Hash& hash,
                     const Allocator& alloc)
         : unordered_set(init, bucket_count,

                          hash, key_equal(), alloc){}
      (15)(since C++14)
      template<container-compatible-range<value_type> R>

      unordered_set(std::from_range_t, R&& rg,
                     size_type bucket_count=/* see description */,
                     const Hash& hash= Hash(),
                     const key_equal& equal= key_equal(),

                     const Allocator& alloc= Allocator());
      (16)(since C++23)
      template<container-compatible-range<value_type> R>

      unordered_set(std::from_range_t, R&& rg,
                     size_type bucket_count,
                     const Allocator& alloc)
         : unordered_set(std::from_range,std::forward<R>(rg),

                          bucket_count, Hash(), key_equal(), alloc){}
      (17)(since C++23)
      template<container-compatible-range<value_type> R>

      unordered_set(std::from_range_t, R&& rg,
                     size_type bucket_count,
                     const Hash& hash,
                     const Alloc& alloc)
         : unordered_set(std::from_range,std::forward<R>(rg),

                          bucket_count, hash, key_equal(), alloc){}
      (18)(since C++23)

      Constructs new container from a variety of data sources. Optionally uses user suppliedbucket_count as a minimal number of buckets to create,hash as the hash function,equal as the function to compare keys andalloc as the allocator.

      1-5) Constructs empty container. Setsmax_load_factor() to1.0. For the default constructor, the number of buckets is unspecified.
      6-8) Constructs the container with the contents of the range[firstlast). Setsmax_load_factor() to1.0. If multiple elements in the range have keys that compare equivalent, it is unspecified which element is inserted (pendingLWG2844).
      9,10) Copy constructor. Constructs the container with the copy of the contents ofother, copies the load factor, the predicate, and the hash function as well. Ifalloc is not provided, allocator is obtained by callingstd::allocator_traits<allocator_type>::select_on_container_copy_construction(other.get_allocator()).

      The template parameterAllocator is only deduced from the first argument while used inclass template argument deduction.

      (since C++23)
      11,12)Move constructor. Constructs the container with the contents ofother using move semantics. Ifalloc is not provided, allocator is obtained by move-construction from the allocator belonging toother.

      The template parameterAllocator is only deduced from the first argument while used inclass template argument deduction.

      (since C++23)
      13-15)Initializer-list constructor. Constructs the container with the contents of the initializer listinit, same asunordered_set(init.begin(), init.end()).
      16-18) Constructs the container with the contents ofrg. If multiple elements in the range have keys that compare equivalent, it is unspecified which element is inserted (pendingLWG2844).

      Contents

      [edit]Parameters

      alloc - allocator to use for all memory allocations of this container
      bucket_count - minimal number of buckets to use on initialization. If it is not specified, an unspecified default value is used
      hash - hash function to use
      equal - comparison function to use for all key comparisons of this container
      first, last - the pair of iterators defining the sourcerange of elements to copy
      rg - acontainer compatible range, that is, aninput_range whose elements are convertible tovalue_type
      other - another container to be used as source to initialize the elements of the container with
      init - initializer list to initialize the elements of the container with
      Type requirements
      -
      InputIt must meet the requirements ofLegacyInputIterator.

      [edit]Complexity

      1-5) Constant.
      6-8) Average case linear (i.e.O(N), whereN isstd::distance(first, last)), worst case quadratic, i.e.O(N2).
      9,10) Linear in size ofother.
      11,12) Constant. Ifalloc is given andalloc!= other.get_allocator(), then linear.
      13-15) Average caseO(N) (N isstd::size(init)), worst caseO(N2).
      16-18) Average caseO(N) (N isranges::distance(rg)), worst caseO(N2).

      [edit]Exceptions

      Calls toAllocator::allocate may throw.

      [edit]Notes

      [edit]
      After container move construction (overload(11,12)), references, pointers, and iterators (other than the end iterator) toother remain valid, but refer to elements that are now in*this. The current standard makes this guarantee via the blanket statement in[container.reqmts]/67, and a more direct guarantee is under consideration viaLWG issue 2321.

      Although not formally required until C++23, some implementations have already put the template parameterAllocator intonon-deduced contexts in earlier modes.

      Feature-test macroValueStdFeature
      __cpp_lib_containers_ranges202202L(C++23)Ranges-aware construction and insertion; overloads(16-18)

      [edit]Example

      This section is incomplete
      Reason: no example

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 2193C++11the default constructor(1) was explicitmade non-explicit
      LWG 2230C++11the semantics of overload(13) was not specifiedspecified

      [edit]See also

      assigns values to the container
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/container/unordered_set/unordered_set&oldid=135474"

      [8]ページ先頭

      ©2009-2025 Movatter.jp