でブラケット演算子を使用しようとしていますboost::bimap
が、成功しません。
私が解決しようとしている問題にはbimap
、次の要件を満たす が必要です。
- 左 ソート、一意
int
- 正しい、一意ではない、ソートされていないタイプ
これにより、次のように選択するようtypedef
になりましたbimap
。
typedef bimap<int, multiset_of<int> > bm;
このタイプでブラケット演算子を使用したいのですが、うまくいきません。これは私が使用するコードです。
#include <iostream>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
using namespace std;
using namespace boost::bimaps;
int main()
{
typedef bimap<int, multiset_of<int> > bm;
bm mapping;
mapping.insert(bm::value_type(1, 1));
mapping.insert(bm::value_type(2, 1));
mapping.insert(bm::value_type(3, 4));
for (auto it : {1 , 2, 3})
mapping.left[it] = it;
for (auto it : mapping.left)
cout << "{ " << it.first << ", " << it.second << " } ";
return 0;
}
これにより、重要なビットが存在するように見える長いコンパイルエラーが発生します
/usr/include/boost/bimap/detail/map_view_base.hpp:351:9: error: no matching function for call to 'assertion_failed'
BOOST_BIMAP_STATIC_ERROR( OPERATOR_BRACKET_IS_NOT_SUPPORTED, (Derived));
(完全なライブ ライブ サンプルとコンパイラ出力は次の場所にあります: rextester )
以下の解決策を試しましたが、それでもエラーが発生します。
#include <iostream>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
using namespace std;
using namespace boost::bimaps;
int main()
{
typedef bimap<int, multiset_of<int> > bm;
typedef bm::left_map map_type;
bm mapping;
map_type& m = mapping.left;
mapping.insert(bm::value_type(1, 1));
mapping.insert(bm::value_type(2, 1));
mapping.insert(bm::value_type(3, 4));
for (auto it : {1 , 2, 3})
m[it] = it;
for (auto it : mapping.left)
cout << "{ " << it.first << ", " << it.second << " } ";
return 0;
}
bimap
要件を満たし、ブラケット演算子をサポートするを宣言するにはどうすればよいですか?