Skip to content

Files

Latest commit

 

History

History
132 lines (109 loc) · 7.06 KB

op_deduction_guide.md

File metadata and controls

132 lines (109 loc) · 7.06 KB

推論補助

  • flat_map[meta header]
  • std[meta namespace]
  • flat_multimap[meta class]
  • cpp23[meta cpp]
namespace std {
  // 説明用の型
  template <class InputIterator>
  using iter_key_t = remove_const_t<typename iterator_traits<InputIterator>::value_type::first_type>;
  template <class InputIterator>
  using iter_val_t = typename iterator_traits<InputIterator>::value_type::second_type;
  template<ranges::input_range Range>
  using range_key_t = remove_const_t<typename ranges::range_value_t<Range>::first_type>;
  template<ranges::input_range Range>
  using range_val_t = typename ranges::range_value_t<Range>::second_type;
  template<class Allocator, class T>
  using alloc_rebind = typename allocator_traits<Allocator>::template rebind_alloc<T>;

  template<class KeyContainer, class MappedContainer,
           class Compare = less<typename KeyContainer::value_type>>
  flat_multimap(KeyContainer, MappedContainer, Compare = Compare())
    -> flat_multimap<typename KeyContainer::value_type, typename MappedContainer::value_type,
                Compare, KeyContainer, MappedContainer>;                                      // (1)

  template<class KeyContainer, class MappedContainer, class Allocator>
  flat_multimap(KeyContainer, MappedContainer, Allocator)
    -> flat_multimap<typename KeyContainer::value_type, typename MappedContainer::value_type,
                less<typename KeyContainer::value_type>, KeyContainer, MappedContainer>;      // (2)

  template<class KeyContainer, class MappedContainer, class Compare, class Allocator>
  flat_multimap(KeyContainer, MappedContainer, Compare, Allocator)
    -> flat_multimap<typename KeyContainer::value_type, typename MappedContainer::value_type,
                Compare, KeyContainer, MappedContainer>;                                      // (3)

  template<class KeyContainer, class MappedContainer,
           class Compare = less<typename KeyContainer::value_type>>
  flat_multimap(sorted_equivalent_t, KeyContainer, MappedContainer, Compare = Compare())
    -> flat_multimap<typename KeyContainer::value_type, typename MappedContainer::value_type,
                Compare, KeyContainer, MappedContainer>;                                      // (4)

  template<class KeyContainer, class MappedContainer, class Allocator>
  flat_multimap(sorted_equivalent_t, KeyContainer, MappedContainer, Allocator)
    -> flat_multimap<typename KeyContainer::value_type, typename MappedContainer::value_type,
                less<typename KeyContainer::value_type>, KeyContainer, MappedContainer>;      // (5)

  template<class KeyContainer, class MappedContainer, class Compare, class Allocator>
  flat_multimap(sorted_equivalent_t, KeyContainer, MappedContainer, Compare, Allocator)
    -> flat_multimap<typename KeyContainer::value_type, typename MappedContainer::value_type,
                Compare, KeyContainer, MappedContainer>;                                      // (6)

  template<class InputIterator, class Compare = less<iter_key_t<InputIterator>>>
  flat_multimap(InputIterator, InputIterator, Compare = Compare())
    -> flat_multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Compare>;          // (7)

  template<class InputIterator, class Compare = less<iter_key_t<InputIterator>>>
  flat_multimap(sorted_equivalent_t, InputIterator, InputIterator, Compare = Compare())
    -> flat_multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Compare>;          // (8)

  template<ranges::input_range R, class Compare = less<range_key_t<R>>,
           class Allocator = allocator<byte>>
  flat_multimap(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
    -> flat_multimap<range_key_t<R>, range_val_t<R>, Compare,
                vector<range_key_t<R>, alloc_rebind<Allocator, range_key_t<R>>>,
                vector<range_val_t<R>, alloc_rebind<Allocator, range_val_t<R>>>>;             // (9)

  template<ranges::input_range R, class Allocator>
  flat_multimap(from_range_t, R&&, Allocator)
    -> flat_multimap<range_key_t<R>, range_val_t<R>, less<range_key_t<R>>,
                vector<range_key_t<R>, alloc_rebind<Allocator, range_key_t<R>>>,
                vector<range_val_t<R>, alloc_rebind<Allocator, range_val_t<R>>>>;             // (10)

  template<class Key, class T, class Compare = less<Key>>
  flat_multimap(initializer_list<pair<Key, T>>, Compare = Compare())
    -> flat_multimap<Key, T, Compare>;                                                        // (11)

  template<class Key, class T, class Compare = less<Key>>
  flat_multimap(sorted_equivalent_t, initializer_list<pair<Key, T>>, Compare = Compare())
    -> flat_multimap<Key, T, Compare>;                                                        // (12)
  • vector[link /reference/vector/vector.md]
  • from_range_t[link ../../ranges/from_range_t.md]
  • sorted_equivalent_t[link ../sorted_equivalent_t.md]
  • remove_const_t[link /reference/type_traits/remove_const.md]
  • pair[link /reference/utility/pair.md]
  • iterator_traits[link /reference/iterator/iterator_traits.md]
  • less[link /reference/functional/less.md]
  • allocator[link /reference/memory/allocator.md]
  • initializer_list[link /reference/initializer_list/initializer_list.md]
  • ranges::input_range[link /reference/ranges/input_range.md]
  • allocator_traits[link /reference/memory/allocator_traits.md]
  • byte[link /reference/cstddef/byte.md]

概要

std::flat_multimapクラステンプレートの型推論補助。

  • (1) : キーのコンテナ、値のコンテナ、比較関数からの推論
  • (2) : キーのコンテナ、値のコンテナ、アロケータからの推論
  • (3) : キーのコンテナ、値のコンテナ、比較関数、アロケータからの推論
  • (4) : キーのコンテナ、値のコンテナ、比較関数からの推論
  • (5) : キーのコンテナ、値のコンテナ、アロケータからの推論
  • (6) : キーのコンテナ、値のコンテナ、比較関数、アロケータからの推論
  • (7) : イテレータ範囲、比較関数からの推論
  • (8) : イテレータ範囲、比較関数からの推論
  • (9) : Range、比較関数、アロケータからの推論
  • (10) : Range、アロケータからの推論
  • (11) : 初期化子リスト、比較関数からの推論
  • (12) : 初期化子リスト、比較関数からの推論

備考

  • C++23時点において、flat_multimapの推論補助は使いにくい。これはイテレータ範囲や組でのキーの型がconst Keyとなっているためだ。この使いにくさは、将来の言語拡張で改良される可能性がある。
    flat_multimap m = {{1, 1}, {2, 2}, {3, 3}}; // コンパイルエラー! 初期化子リストからconst Keyを導出できない
    flat_multimap m2 = initializer_list<pair<const int, int>>({{1, 1}, {2, 2}, {3, 3}}); // OK

バージョン

言語

  • C++23

処理系

参照