![]() |
赤紫蘇2.リファレンス |
||
|
配列 |
|||
| akaxiso2.0-beta1 | |||
|
|
|||
配列クラスは、STLコンテナを用いて定義します。 STLコンテナ以外のコンテナであっても、クラスインターフェースとして、STLコンテナと同等のメソッドを実装していれば、使用することができます。 以下の二種類のコンテナを扱うことができます。 ・順序つきコンテナ(sequential container) std::list<>、std::vector<>などのように、push_back()メソッドにより、要素を挿入可能であり、挿入された要素が、挿入順に並ぶコンテナです。 template<class I>
struct sequential {
typedef I value_type;
struct iterator (implementation defined.);
struct const_iterator (implementation defined);
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
void clear();
bool empty() const;
size_t size() const;
void push_back(const I& i);
};
・連想コンテナ(associative container) std::map<>、std::set<>のように、指定されたキーによりコンテナ内の順序付けが可能なコンテナです。 template<class I>
struct associative {
typedef (container defined) value_type;
struct iterator (implementation defined.);
struct const_iterator (implementation defined);
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
void clear();
bool empty() const;
size_t size() const;
std::pair<value_type, bool> insert(const I& i);
};
現在、sorted associative containerのみに対応しています。 (若干の実装の追加で、multiple associative containerに対応することも、可能です。) 配列の型宣言 通常の(STL)コンテナの使用法と同様です。 typedef std::vector<long> long_array; と定義することで、long型の配列を定義することができます。 leafクラスの定義 配列に対するleafクラスを定義するためのテンプレートが、準備されています。 順序つきコンテナのleafクラスを定義する場合には、aka::sequential_array<>テンプレートを使います。宣言は以下の通りです。 template<class T, class VL=xiso::leaf<typename T::value_type> > class sequential_array; Tは、コンテナクラス名、VLは、要素の値を処理するleafクラスを指定します。VLは、デフォルト値として、xiso::leaf<typename T::value_type>を持ちます。明示的にコンテナ要素のleafクラスを指定する時には、VLに、leafクラス名を与えてください。 上記のlong_arrayに対応するleafクラスの定義は、以下のようになります。 namespace xiso {
template<>
struct leaf<long_array> : aka::sequential_array<long_array> { };
}
また、xiso::leaf<>を用いず、leafクラス名を指定する場合には、以下の通りです。 typedef aka::sequential_array<long_array> long_array_leaf; 連想コンテナの場合には、aka::associative_array<>テンプレートを使用します。使用法は、aka::sequential_array<>テンプレートと同様です。 template<class T, class VL=xiso::leaf<TYPENAME T::value_type> > class associative_array; |
|||
