Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Boost::列表_无法对稍微复杂的数据结构进行模板推导_C++_Boost - Fatal编程技术网

C++ Boost::列表_无法对稍微复杂的数据结构进行模板推导

C++ Boost::列表_无法对稍微复杂的数据结构进行模板推导,c++,boost,C++,Boost,我必须使用跨平台代码。现在,我一直在使用VS2012,它不支持C++11,统一初始化。因此,我使用的是boost::list_of 对于简单的情况,这是可行的。但是,对于稍微复杂的数据结构,这似乎不起作用 #include <iostream> #include <boost/assign.hpp> #include <boost/assign/list_of.hpp> #include <tuple> using namespace std; u

我必须使用跨平台代码。现在,我一直在使用
VS2012
,它不支持
C++11
,统一初始化。因此,我使用的是
boost::list_of

对于简单的情况,这是可行的。但是,对于稍微复杂的数据结构,这似乎不起作用

#include <iostream>
#include <boost/assign.hpp>
#include <boost/assign/list_of.hpp>
#include <tuple>
using namespace std;
using namespace boost::assign;

int main() {

class NodeInfo
{
    public:
        NodeInfo (int Parent, int childLeft, int childRight) :
            m_parent (Parent), m_childLeft(childLeft), m_childRight(childRight)
            {   

            }
        private:
            int m_parent;
            int m_childLeft;
            int m_childRight;
};
typedef std::vector<NodeInfo> MyData1;
MyData1 expData =  list_of(NodeInfo(1,2,3)) (NodeInfo(3,4,5));

typedef std::tuple<int , std::vector<NodeInfo>> MyData2;
MyData2 expData21 =  std::make_tuple(10 , expData);

 // I would have really liked the following:
 // error:
 MyData2 expData22 =  std::make_tuple(10 , list_of(NodeInfo(1,2,3) (NodeInfo(3,4,5) )));

//error:From the example in boost doc, this should work. 
MyData2 expData3 =  list_of<MyData2> (std::make_tuple(10 , expData));

MyData2 expData4;
// error: Most probably need to write my own list_inserter for MyTest,
// after turning MyTest into a class. 
// I really don't want to go this route, if the other options are at all 
// possible. Why extend the boost library, if it's at all possible ? 
insert( expData4 )
    ( std::make_tuple(10 , expData) )( std::make_tuple(20 , expData) ); 

return 0;
}
#包括
#包括
#包括
#包括
使用名称空间std;
使用名称空间boost::assign;
int main(){
类节点信息
{
公众:
NodeInfo(int-Parent、int-childLeft、int-childRight):
m_parent(parent)、m_childLeft(childLeft)、m_childRight(childRight)
{   
}
私人:
国际母校;
int m_childLeft;
int m_childRight;
};
typedef std::vector MyData1;
MyData1 expData=NodeInfo(1,2,3))(NodeInfo(3,4,5))的列表;
typedef std::元组MyData2;
MyData2 expData21=std::make_tuple(10,expData);
//我真的很喜欢以下几点:
//错误:
MyData2 expData22=std::make_tuple(10,NodeInfo(1,2,3)(NodeInfo(3,4,5))的列表);
//错误:根据boost文档中的示例,这应该可以工作。
MyData2 expData3=列表(std::make_tuple(10,expData));
MyData2 expData4;
//错误:很可能需要为MyTest编写自己的列表插入器,
//将MyTest转换为类之后。
//我真的不想走这条路,如果其他的选择是有的话
//可能。如果可能的话,为什么要扩展boost库?
插入(expData4)
(std::make_tuple(10,expData))(std::make_tuple(20,expData));
返回0;
}
我在这里添加了部分代码。

你只是把括号弄错了。以下方面应起作用:

MyData2 expData22 =  std::make_tuple(10 , list_of(NodeInfo(1,2,3))(NodeInfo(3,4,5)));

事实上,使这项工作顺利进行的最佳方法是扩展库(或者只编写自己的帮助函数)

然而,您尝试的东西从来都不是功能。显示了如何从的列表_分配给向量:

Tuple mytuple2 = std::make_tuple(10, 
        list_of(NodeInfo(1, 2, 3))(NodeInfo(3, 4, 5)).to_container(std::get<1>(mytuple2))
    );

测试它会很简单,当然我把括号搞错了,我试了一些东西。但这不是问题所在。正如@sehe正确地指出的那样,问题出在其他地方,我错过了to_容器;从文件上看,我不清楚,什么样的奉献可以被列表所支持。谢谢你帮我解决了这个问题。现在,我将带着它跑。我可能会像你指出的那样写我自己的列表插入器
Tuple mytuple2 = std::make_tuple(10, 
        list_of(NodeInfo(1, 2, 3))(NodeInfo(3, 4, 5)).to_container(std::get<1>(mytuple2))
    );
#include <iostream>
#include <boost/assign.hpp>
#include <boost/assign/list_of.hpp>
#include <tuple>
using namespace std;
using namespace boost::assign;

int main() {

    class NodeInfo {
      public:
        NodeInfo(int Parent, int childLeft, int childRight)
                : m_parent(Parent), m_childLeft(childLeft), m_childRight(childRight) {}

      private:
        int m_parent;
        int m_childLeft;
        int m_childRight;
    };

    typedef std::vector<NodeInfo> NodeInfos;
    NodeInfo node1(1,2,3), node2(3,4,5);
    NodeInfos infos = list_of(node1)(node2);

    typedef std::tuple<int, std::vector<NodeInfo> > Tuple;
    Tuple mytuple = std::make_tuple(10, infos);

    // I would have really liked the following:
    Tuple mytuple2 = std::make_tuple(10, 
            list_of(NodeInfo(1, 2, 3))(NodeInfo(3, 4, 5)).to_container(std::get<1>(mytuple2))
        );

    std::vector<Tuple> 
        mytuples = list_of<Tuple>(std::make_tuple(10, infos)),
        mytuples2;

    //// still figuring this out:
    // insert(mytuples2)(Tuple(10, infos))(Tuple(20, infos));
}