0
부스트 multi_index를 사용하기 시작했으며 지금까지 시퀀스 된 유형과 복합 키 unorderd 해시를 제공하는 컨테이너가 있습니다.boost :: multi_index by size_t index 순차 위치로 반복 하시겠습니까?
std :: vector 또는 std :: 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;
};
내가 말하는거다 기능은 다음과 같습니다 : VS2010에서 오류
// 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();
}
}
사진은 (오른쪽에있는 시계 창을 보면) :
여기 은 아래에있는 내 코드입니다
? 어떤 오류가 발생하고 있습니까? –
반복기가 어떤 이유로 유효하지 않습니다. 애플리케이션을 디버깅 할 때'm_elements' 내에 ** 노드가 ** 있다고 말합니다. 그러나'index = 0'으로'index_type.begin()'에서 반환 된 itor는 유효하지 않습니다 ... 어떻게 잘못 될 수 있는지 모르겠습니다. 내가 할 수 있으면 질문에 스크린 샷을 첨부 할 것입니다. – Sent1nel
사실 나는 방금 그것을 해결했습니다. 'for (UInt i = 0; i
Sent1nel