名稱空間
變體
操作

std::flat_map 的推導指南

來自 cppreference.com
< cpp‎ | 容器‎ | flat map
 
 
 
 
在標頭檔案 <flat_map> 中定義
template< class KeyContainer, class MappedContainer,

          class Compare = std::less<typename KeyContainer::value_type> >
flat_map( KeyContainer, MappedContainer, Compare = Compare() )
    -> flat_map<typename KeyContainer::value_type,
                typename MappedContainer::value_type,

                Compare, KeyContainer, MappedContainer>;
(1) (C++23 起)
template< class KeyContainer, class MappedContainer, class Allocator >

flat_map( KeyContainer, MappedContainer, Allocator )
    -> flat_map<typename KeyContainer::value_type,
                typename MappedContainer::value_type,
                std::less<typename KeyContainer::value_type>,

                KeyContainer, MappedContainer>;
(2) (C++23 起)
template< class KeyContainer, class MappedContainer,

          class Compare, class Allocator >
flat_map( KeyContainer, MappedContainer, Compare, Allocator )
    -> flat_map<typename KeyContainer::value_type,
                typename MappedContainer::value_type,

                Compare, KeyContainer, MappedContainer>;
(3) (C++23 起)
template< class KeyContainer, class MappedContainer,

          class Compare = std::less<typename KeyContainer::value_type> >
flat_map( std::sorted_unique_t, KeyContainer, MappedContainer,
          Compare = Compare() )
    -> flat_map<typename KeyContainer::value_type,
                typename MappedContainer::value_type,

                Compare, KeyContainer, MappedContainer>;
(4) (C++23 起)
template< class KeyContainer, class MappedContainer, class Allocator >

flat_map( std::sorted_unique_t, KeyContainer, MappedContainer,
          Allocator )
    -> flat_map<typename KeyContainer::value_type,
                typename MappedContainer::value_type,
                std::less<typename KeyContainer::value_type>,

                KeyContainer, MappedContainer>;
(5) (C++23 起)
template< class KeyContainer, class MappedContainer,

          class Compare, class Allocator>
flat_map( std::sorted_unique_t, KeyContainer, MappedContainer,
          Compare, Allocator )
    -> flat_map<typename KeyContainer::value_type,
                typename MappedContainer::value_type,

                Compare, KeyContainer, MappedContainer>;
(6) (C++23 起)
template< class InputIter,

          class Compare = std::less</*iter-key-type*/<InputIter>> >
flat_map( InputIter, InputIter, Compare = Compare() )
    -> flat_map</*iter-key-type*/<InputIter>,

                /*iter-mapped-type*/<InputIter>, Compare>;
(7) (C++23 起)
template< class InputIter,

          class Compare = std::less</*iter-key-type*/<InputIter>> >
flat_map( std::sorted_unique_t, InputIter, InputIter,
          Compare = Compare() )
    -> flat_map</*iter-key-type*/<InputIter>,

                /*iter-mapped-type*/<InputIter>, Compare>;
(8) (C++23 起)
template< ranges::input_range R,

          class Compare = std::less</*range-key-type*/<R>>,
          class Allocator = allocator<byte> >
flat_map( std::from_range_t, R&&, Compare = Compare(),
          Allocator = Allocator() )
    -> flat_map</*range-key-type*/<R>, /*range-mapped-type*/<R>, Compare,
                std::vector</*range-key-type*/<R>,
                            /*alloc-rebind*/<Allocator,
                                             /*range-key-type*/<R>>>,
                std::vector</*range-mapped-type*/<R>,
                            /*alloc-rebind*/<Allocator,

                                             /*range-mapped-type*/<R>>>>;
(9) (C++23 起)
template< ranges::input_range R, class Allocator >

flat_map( std::from_range_t, R&&, Allocator )
    -> flat_map</*range-key-type*/<R>, /*range-mapped-type*/<R>,
                std::less</*range-key-type*/<R>>,
                std::vector</*range-key-type*/<R>,
                            /*alloc-rebind*/<Allocator,
                                             /*range-key-type*/<R>>>,
                std::vector</*range-mapped-type*/<R>,
                            /*alloc-rebind*/<Allocator,

                                             /*range-mapped-type*/<R>>>>;
(10) (C++23 起)
template< class Key, class T, class Compare = std::less<Key> >

flat_map( std::initializer_list<pair<Key, T>>, Compare = Compare() )

    -> flat_map<Key, T, Compare>;
(11) (C++23 起)
template< class Key, class T, class Compare = std::less<Key> >

flat_map( std::sorted_unique_t, std::initializer_list<pair<Key, T>>,
          Compare = Compare() )

    -> flat_map<Key, T, Compare>;
(12) (C++23 起)

提供了這些推導指南,以允許從以下情況進行推導:

1) 鍵容器、對映容器和比較器。
2) 鍵容器、對映容器和分配器。
3) 鍵容器、對映容器、比較器和分配器。
4) std::sorted_unique_t 標籤、鍵容器、對映容器和比較器。
5) std::sorted_unique_t 標籤、鍵容器、對映容器和分配器。
6) std::sorted_unique_t 標籤、鍵容器、對映容器、比較器和分配器。
7) 迭代器範圍和比較器。
8) std::sorted_unique_t 標籤、迭代器範圍和比較器。
9) std::from_range_t 標籤、input_range 範圍、比較器和分配器。
10) std::from_range_t 標籤、input_range 範圍和分配器。
11) std::initializer_list 和比較器。
12) std::sorted_unique_t 標籤、std::initializer_list 和比較器。

這些過載僅在 InputIt 滿足 LegacyInputIteratorAlloc 滿足 Allocator,並且 Comp 不滿足 Allocator 時參與過載決議。

注意:庫確定型別不滿足 LegacyInputIterator 的程度未指定,但至少整數型別不符合輸入迭代器。同樣,它確定型別不滿足 Allocator 的程度未指定,但至少成員型別 Alloc::value_type 必須存在,並且表示式 std::declval<Alloc&>().allocate(std::size_t{}) 在作為未求值運算元處理時必須是格式良好的。

[編輯] 示例