English 中文(简体)
相应地提升:乘以大小指数
原标题:Iterate to sequential position in boost::multi_index by size_t index?
  • 时间:2011-05-05 12:25:43
  •  标签:
  • c++
  • boost

我刚刚开始使用加固多功能指数,迄今为止,有一个集装箱,装配了有序的类型和混合的关键未定的斜体。

我想做的是,如果集装箱是 st的:ctor子或 st子:list子,那么它就能够进入。 通过这一方式,采用<代码>size_t index。

我的守则如下:

// tags
struct linear { };
struct semantic { };
struct semantic_and_index { };

// typedefs for multi_index
typedef boost::multi_index::sequenced< 
    boost::multi_index::tag<linear>
> LinearIndex;

typedef boost::multi_index::composite_key<
    CVertexElement,
    boost::multi_index::const_mem_fun<CVertexElement, Buffer::VertexSemantic, &CVertexElement::GetVertexSemantic>,
    boost::multi_index::const_mem_fun<CVertexElement, UInt, &CVertexElement::GetSemanticIndex> 
> CompositeSemanticIndex;

typedef boost::multi_index::hashed_non_unique<
    boost::multi_index::tag<semantic_and_index>,
    CompositeSemanticIndex
> SemanticAndIDIndex;

typedef boost::multi_index::hashed_non_unique<
    boost::multi_index::tag<semantic>,
    boost::multi_index::const_mem_fun<CVertexElement, Buffer::VertexSemantic, &CVertexElement::GetVertexSemantic> 
> SemanticIndex;

class CVertexFormat
{
public:
    typedef boost::multi_index::multi_index_container <
        CVertexElementPtr,
        boost::multi_index::indexed_by <
            LinearIndex,
            SemanticAndIDIndex,
            SemanticIndex
        > // index_by
    > ElementContainer; 

      // etc...

protected:
    ElementContainer m_elements;
};

我指的是:

// this function fails! :(
CVertexElementPtr CVertexFormat::GetElement(size_t index) const 
{
    //sequenced_index.
    typedef ElementContainer::index<linear>::type element_by_linear;
    const element_by_linear& index_type = m_elements.get<linear>();

    if ( index < index_type.size() )
    {
        auto itor = index_type.begin();
        for (UInt i = 0; i < index_type.size(); ++i)
            ++itor;

        const CVertexElementPtr& pElement = (*itor);        
        return pElement;
    }
    else
    {
        assert(!"Invalid index called for GetElement");
        return CVertexElementPtr();
    }
}

• 对2010年(右边看望窗):

高度喷雾管

最佳回答

问题通过修改以下功能得到解决:

正确的职能是:

CVertexElementPtr CVertexFormat::GetElement(size_t index) const
{
    //sequenced_index.
    typedef ElementContainer::index<linear>::type element_by_linear;
    const element_by_linear& index_type = m_elements.get<linear>();

    size_t size = index_type.size();
    if ( index < size )
    {
        auto itor = index_type.begin();
        for (UInt i = 0; i < index; ++i)
            ++itor;

        const CVertexElementPtr& pElement = (*itor);        
        return pElement;
    }
    else
    {
        assert( false && ieS("Invalid index called for GetElement") );
        return CVertexElementPtr();
    }
}
问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签