#include <static_container/vector.h> using namespace static_container; vector< int, 10 > c; // int のベクター ( 最大サイズ 10 ) c.max_size(); // = 10 c.size(); // = 0 c.push_back( 5 ); // 5 を末尾に挿入 c.size(); // = 1 c.pop_back(); // 削除 c.size(); // = 0
現在、4バイトアラインにしか対応していない。
#include <static_container/list.h> using namespace static_container; list< int, 10 > c; // int のリスト ( 最大サイズ 10 ) c.max_size(); // = 10 c.size(); // = 0 c.push_back( 5 ); // 5 を末尾に挿入 c.size(); // = 1 c.pop_back(); // 削除 c.size(); // = 0
vector と違い、こいつはアライン問題は、大丈夫だと思う。
static_container::list_node_pool
#include <static_container/lodge_list.h> void test_lodge_list() { list_node_pool< int, 10 > pool; lodge_list< int > list0( pool ); lodge_list< int > list1( pool ); lodge_list< int > list2( pool ); pool.rest(); // = 10 初期状態では、10 個余っています list0.push_back( 100 ); // 100 を list0 に挿入 pool.rest(); // = 9 一つ減ります list0.front(); // = 100 もちろん、back も 100 になります }
現在、もっと良い名前を募集中!
#include <static_container/string.h> using namespace static_container; string< 10 > c; // 最大サイズ 10 の文字列 c.max_size(); // = 10 c.size(); // = 0 c.length(); // = 0 ( size() と同じ ) c.push_back( 5 ); // 5 を末尾に挿入 c.size(); // = 1 c.pop_back(); // 削除 c.size(); // = 0 "" == c; // = true ( C 文字列との比較 ) c < "a"; // = true ( C 文字列との辞書順比較 ) c = "hello"; // 文字列の代入 string< 100 > c100( c ); // 別の型への代入 c100 = c; c100 += c; c100.append( c );
static_container::list_hash
である。多くの場合、hash は list と組み合わせて使われることを想定しているため、最初からそれを組み合わせた list_hash というものも存在する。ほとんどの場合は、これを利用していれば、大きな問題に出会うことも無いであろう。
typedef list_hash< int, int, 10 > int_hash; int_hash ihash; ihash[ 0 ] = 100; ihash[ 5 ] = 20; ihash.size(); // = 2 ihash[ 0 ]; // = 100 ihash[ 5 ]; // = 20 ihash[ 5 ] = 30; 30 == ihash[ 5 ]; // = 30 ihash.size(); // = 2 すでにキーが存在する場合は、サイズが増えない
このライブラリは、boost に依存しています。
http://e-words.jp/w/BSDE383A9E382A4E382BBE383B3E382B9.html
作者への報告があれば、当然喜びますし、より良いライブラリになるでしょう。ただ、報告がなくても、商用利用してかまいませんし、改変をしてもかまいません。
このライブラリ作成にあたって、会社の仲間 ( http://www.pyramid-inc.net/ ) にお世話になりました。謝辞を述べさせていただきます。