[ Web Proxy ]
URL:
Viewing: http://ru.cppreference.com/cpp/container/unordered_map/begin [Back]  [Original]

std::unordered_map::begin, std::unordered_map::cbegin cppreference.com
cppreference.com

std::unordered_map::begin, std::unordered_map::cbegin

cppreference.com
 
C++
(C++20)
(C++20)
(C++11)
(C++20)
/
(C++11)
(C++11)
(C++11)
(C++17)
 
 
 
<tbody>
<tbody> </tbody>
iterator begin() noexcept;
( C++11)
const_iterator begin() const noexcept;
( C++11)
const_iterator cbegin() const noexcept;
( C++11)

unordered_map.

unordered_map - , end()

()

.

.


Example

#include <cmath>
#include <iostream>
#include <unordered_map>

struct Node { double x, y; };

int main() {
    Node nodes[3] = { {1, 0}, {2, 0}, {3, 0} };
    
    // mag - map,   Node     
    std::unordered_map<Node *, double> mag = {
        { nodes,     1 },
        { nodes + 1, 2 },
        { nodes + 2, 3 }
    };
    
    //   y   0   
    for(auto iter = mag.begin(); iter != mag.end(); ++iter){
        auto cur = iter->first; //   Node
        cur->y = mag[cur]; //    cur->y = iter->second;
    }
 
    //    
    for(auto iter = mag.begin(); iter != mag.end(); ++iter){
        auto cur = iter->first;
        mag[cur] = std::hypot(cur->x, cur->y);
        std::cout << " (" << cur->x << ", " << cur->y << ") - ";
        std::cout << iter->second << '\n';
    }

    //  ,      
    for(auto i : mag) {
        auto cur = i.first;
        cur->y = i.second;
        mag[cur] = std::hypot(cur->x, cur->y);
        std::cout << " (" << cur->x << ", " << cur->y << ") - ";
        std::cout << mag[cur] << '\n';
        // ,     std::cout << iter->second << '\n'; , 
        // std::cout << i.second << '\n';    
    }
}

:

 (3, 3) - 4.24264
 (1, 1) - 1.41421
 (2, 2) - 2.82843
 (3, 4.24264) - 5.19615
 (1, 1.41421) - 1.73205
 (2, 2.82843) - 3.4641

See also

(C++11)

(public -) []

Web Proxy Viewer  |  New URL  |  Original Page