How do I get a const_iterator using auto?

前端 未结 8 1783
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-13 08:18

First question: is it possible to \"force\" a const_iterator using auto? For example:

map usa         


        
8条回答
  •  借酒劲吻你
    2020-12-13 08:44

    Since C++17 you can use std::as_const like this:

    #include 
    
    // ...
    
    auto city_it = std::as_const(usa).find("New York");
    

提交回复
热议问题