0
所以我建立了我的boost::mpl::map
對象,其中包含一些鍵和類型的混合。我現在要實例地圖的實例,例如,我在地圖上的每個type
的一個實例:如何實例化並訪問boost mpl類型?
using namespace boost::mpl;
using MyMap = map<
pair<int, double>,
pair<double, double>,
pair<bool, int>>;
int main()
{
// create the map:
MyMap myMap;
// now I want a reference to the element indexed by "int"
using RefType = at<MyMap, int>::type&;
RefType myRef(myMap); // compile error!
}
我得到的錯誤是沿着線的東西:
error: cannot convert 'MyMap {aka map<...>} to blarghh {aka int}
很明顯,我應該獲得某種「索引」值(可能是boost::mpl::map::order
?)。那麼,如何實際訪問(即獲得引用)這些關聯的mpl
容器中的元素?另外,這個(特別是)如何完成的文檔在哪裏?
對不起,我修復了丟失的逗號。我想實例化地圖,使得我有一組實例化的所有'types',然後我想引用其中一個值(爲了這個例子)。 'std'等價物可能會創建一個'tuple'的實例並獲得對其實例化類型之一的引用。這有意義嗎?據我瞭解,你的例子只是創建一個雙精度和對它的引用。 – arman 2014-10-01 03:12:27
我在想也許我需要爲此加強融合?在那種情況下,我的下一個問題是,我如何將我的'boost :: mpl :: map'轉換爲'boost :: fusion :: map',然後我可以實例化? – arman 2014-10-01 03:19:42
你試圖完成的更高層次的目標是什麼?我很難理解你爲什麼需要'{type:default-constructed-other-type}'的映射。 – 2014-10-01 05:47:13