C++에서 Java로 프레임 워크를 포팅하는 중입니다. C++에 대해 많이 알지 못하기 때문에 예상보다 어려워졌습니다. 나는 정말로 이해하지 못하는이 발췌 문장을 발견했다. 누군가 내가 그 선이 무엇을하는지 말해 줄 수 있다면 그것은 굉장 할 것입니다. 삽입이 이루어진 경우 bool
부재 true
이다번역 C++ 스 니펫
/** Heap data, stored as a vector */
std::vector< std::pair< _Tp, _Val > > data;
/** Maps objects to their positions in the data vector */
std::map< _Tp, int> mapping;
//I understand that this method takes a pair of type <_Tp, _Val>
template <class _Tp, class _Val>
void Heap<_Tp,_Val>::push(std::pair< _Tp, _Val > x)
{
int index=data.size();
//Here is where I run into trouble
//I can't seem to figure out what this line is doing
//I know it is inserting a Key-Value pair into the map
//but why is .second being called? and what exactly is this if statement
//checking?
if (mapping.insert(std::make_pair(x.first,index)).second)
{
data.push_back(x);
percolate_up(index);
}
}
오, 감사합니다. 보고 있던 페이지는 한 쌍의 값을 반환합니다. 나는 정보를 입수하는 사이트에보다주의를 기울여야 할 것이다. 감사합니다 –
@Hunter - 쌍을 반환하는 것은 "표준"동작이 아닙니다. VC++를 사용하고 있다고 상상해보십시오. 벡터 삽입에 대한 쌍의 반환에 의존하는 것은 휴대 할 수 없습니다. 그래서 당신이보고 있던 페이지가 틀렸을 수도 있습니다, 그것은 단지 당신의 컴파일러와 일치하지 않습니다. – Michael
@Michael : 벡터 삽입이 아니라지도 삽입이며, C++ 11 표준에 쌍 리턴이 있습니까? C++ 03에서는 유효하지 않습니까? –