const_associative_property_map<UniquePairAssociativeContainer>
このプロパティマップは、std::mapのようなPair Associative Container とUnique Associative Container を 定数型の Lvalue Property Mapに変換するアダプタである。 このアダプタはコンテナの参照を保持するため、コンテナの寿命は、このアダプタの使用期間を包含しなければならない。
#include <iostream>
#include <map>
#include <string>
#include <boost/property_map.hpp>
template <typename ConstAddressMap>
void display(ConstAddressMap address)
{
typedef typename boost::property_traits<ConstAddressMap>::value_type
value_type;
typedef typename boost::property_traits<ConstAddressMap>::key_type key_type;
key_type fred = "Fred";
key_type joe = "Joe";
value_type freds_address = get(address, fred);
value_type joes_address = get(address, joe);
std::cout << fred << ": " << freds_address << "\n"
<< joe << ": " << joes_address << "\n";
}
int
main()
{
std::map<std::string, std::string> name2address;
boost::const_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")));
display(address_map);
return EXIT_SUCCESS;
}
| パラメータ | 説明 | デフォルト |
|---|---|---|
| UniquePairAssociativeContainer | Pair Associative Container と Unique Associative Containerの両者のモデルでなければならない |
In addition the methods and functions required by Lvalue Property Mapに要請されるメソッドと関数に加え、このクラスは以下のメンバを持つ。
property_traits<const_associative_property_map>::value_typeUniquePairAssociativeContainer::data_type. に同じ。
const_associative_property_map()デフォルトコンストラクタ
const_associative_property_map(const UniquePairAssociativeContainer& c)コンストラクタ
const data_type& operator[](const key_type& k) constプロパティをアクセスするための [ ] 演算子。key_typeとdata_typeの型は、 UniquePairAssociativeContainer 内で、定義されている。
template <typename UniquePairAssociativeContainer> const_associative_property_map<UniquePairAssociativeContainer> make_assoc_property_map(const 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) |