简体   繁体   English

std :: map :: insert返回值?

[英]std::map::insert return value?

typedef TriIndex ...
typedef std::map< TriIndex, unsigned int > VertexMap;
VertexMap vertex_map;

for ( size_t i = 0; i < face.size(); ++i ) { 
    for ( size_t j = 0; j < 3; ++j ) {
        std::pair< VertexMap::iterator, bool > rv = vertex_map.insert( std::make_pair(     face.v[j], vert_idx_counter ) );
        if ( rv.second ) {
            //do stuff
        }
    }
}

I took out a snippet from an opengl starter code. 我从opengl入门代码中摘录了一段代码。 I get what it's doing except for the following line: 除了以下行,我了解它的作用:

std::pair< VertexMap::iterator, bool > rv = vertex_map.insert( std::make_pair(     face.v[j], vert_idx_counter ) );

I get that the line declares a pair called rv with an iterator and a boolean value - . 我知道该行声明了一个称为rv的对,其中包含一个迭代器和一个布尔值-。 But on the right hand side, there is vertex_map.insert - but from what i know, insert is a void function. 但是在右侧,有vertex_map.insert-但据我所知,insert是一个void函数。 How do you get a pair from inserting a pair to vertex map? 从对中插入对如何获得对?

vertex_map与'std :: map <TriIndex,unsigned int>'相同,因此您正在调用地图的插入函数,有关更多详细信息,请参阅文档std :: map :: insert

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM