C++ Boost

associative_property_map<UniquePairAssociativeContainer>

このプロパティマップは、std::mapのようなPair Associative Container と、Unique Associative Container の任意の型をmutableなLvalue Property Map(左辺値プロパティマップ)に変換するアダプタである。 アダプタは、コンテナへのリファレンスしか保持しないことに注意されたい。コンテナの寿命は、このアダプタの使用期間を包含しなければならない。

Example

example1.cpp:
#include <iostream>
#include <map>
#include <string>
#include <boost/property_map.hpp>


template <typename AddressMap>
void foo(AddressMap address)
{
  typedef typename boost::property_traits<AddressMap>::value_type value_type;
  typedef typename boost::property_traits<AddressMap>::key_type key_type;

  value_type old_address, new_address;
  key_type fred = "Fred";
  old_address = get(address, fred);
  new_address = "384 Fitzpatrick Street";
  put(address, fred, new_address);

  key_type joe = "Joe";
  value_type& joes_address = address[joe];
  joes_address = "325 Cushing Avenue";
}

int
main()
{
  std::map<std::string, std::string> name2address;
  boost::associative_property_map< std::map<std::string, std::string> >
    address_map(name2address);

  name2address.insert(make_pair(std::string("Fred"), 
				std::string("710 West 13th Street")));
  name2address.insert(make_pair(std::string("Joe"), 
				std::string("710 West 13th Street")));

  foo(address_map);
  
  for (std::map<std::string, std::string>::iterator i = name2address.begin();
       i != name2address.end(); ++i)
    std::cout << i->first << ": " << i->second << "\n";

  return EXIT_SUCCESS;
}

定義されている場所

boost/property_map.hpp

以下のコンセプトのモデル

Lvalue Property Map

テンプレートパラメータ

パラメータ説明デフォルト
UniquePairAssociativeContainer Pair Associative ContainerUnique Associative Containerのモデルでなければいけない  

メンバ

Lvalue Property Mapに対して要求されるメソッドと関数に加え、このクラスは以下のメンバ関数を持たなければならない。


property_traits<associative_property_map>::value_type
この型は、 UniquePairAssociativeContainer::data_typeと等しい。
associative_property_map()
デフォルトコンストラクタ
associative_property_map(UniquePairAssociativeContainer& c)
コンストラクタ
data_type& operator[](const key_type& k) const
プロパティのアクセスに用いる [ ] 演算子。 key_type型とdata_type型は、UniquePairAssociativeContainer内部にて定義される。

非メンバ関数


  template <typename UniquePairAssociativeContainer>
  associative_property_map<UniquePairAssociativeContainer>
  make_assoc_property_map(UniquePairAssociativeContainer& c);
連想プロパティマップを簡便に生成するための関数。


Copyright © 2002 Jeremy Siek, Indiana University (jsiek@osl.iu.edu)
Lie-Quan Lee, Indiana University (llee1@osl.iu.edu)
Andrew Lumsdaine, Indiana University (lums@osl.iu.edu)