开发者

visual c++ 2010 internal error with boost::multi_index?

开发者 https://www.devze.com 2023-01-30 09:02 出处:网络
I\'m using boost::multi_index with visual studio 2010, and it seems to crash when used with boost::const_mem_fun and virtual class methods :

I'm using boost::multi_index with visual studio 2010, and it seems to crash when used with boost::const_mem_fun and virtual class methods :

class Node
{
public:
    virtual const std::string& getValue() const {return m_strValue;}

protected:
    std::string m_strValue;

private:
    struct byValue{};
    typedef boost::multi_index_container<
     boost::shared_ptr<Node>,
     boost::multi_index::indexed_by<
      boost::multi_index::random_access<>,
      boost::multi_index::ordered_non_unique<
       boost::multi_index::tag<byValue>,
       boost::multi_index::const_mem_fun<Node, const std::string& , &Node::getValue>
      >
     >
    > NodeList;
};

when compiling this, visual crash with this kind of message :

fatal error C1001: An internal error has occurred in the compiler.
1> (compiler file 'msc1.cpp', line 1420)
1> To work around this problem, try simplifying or开发者_C百科 changing the program near the locations listed above.
1> Please choose the Technical Support command on the Visual C++ 
1> Help menu, or open the Technical Support help file for more information

but if Node::getValue isn't virtual, the compilation is ok. is there a way to go around this ?


You can work around this compiler bug by using a user-defined key extractor:

class Node
{
public:
    virtual const std::string& getValue() const {return m_strValue;}

protected:
    std::string m_strValue;

private:
    struct KeyExtractor
    {
      typedef std::string result_type;

      const result_type& operator()(const boost::shared_ptr<Node>& p) const
      {
          return p->getValue();
      }        
    };

    struct byValue{};

    typedef boost::multi_index_container<
     boost::shared_ptr<Node>,
     boost::multi_index::indexed_by<
      boost::multi_index::random_access<>,
      boost::multi_index::ordered_non_unique<
       boost::multi_index::tag<byValue>,
       KeyExtractor
      >
     >
    > NodeList;
};


Report the bug to Microsoft.

No matter how weird the code is, the compiler should not crash.

0

精彩评论

暂无评论...
验证码 换一张
取 消