C++ Boost

const_associative_property_map<UniquePairAssociativeContainer>

このプロパティマップは、std::mapのようなPair Associative ContainerUnique Associative Container を 定数型の Lvalue Property Mapに変換するアダプタである。 このアダプタはコンテナの参照を保持するため、コンテナの寿命は、このアダプタの使用期間を包含しなければならない。

Example

example1.cpp:
#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;
}


定義されている場所

boost/property_map.hpp

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

Lvalue Property Map

テンプレートパラメータ

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

メンバ

In addition the methods and functions required by Lvalue Property Mapに要請されるメソッドと関数に加え、このクラスは以下のメンバを持つ。


property_traits<const_associative_property_map>::value_type
UniquePairAssociativeContainer::data_type. に同じ。
const_associative_property_map()
デフォルトコンストラクタ
const_associative_property_map(const UniquePairAssociativeContainer& c)
コンストラクタ
const data_type& operator[](const key_type& k) const
プロパティをアクセスするための [ ] 演算子。key_typedata_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)