Invoking begin and end via using-directive?

后端 未结 4 1521
醉酒成梦
醉酒成梦 2021-02-19 01:32

The established idiom for invoking swap is:

using std::swap
swap(foo, bar);

This way, swap can be overloaded for user

4条回答
  •  囚心锁ツ
    2021-02-19 02:09

    If your some_container is standard container, std:: prefix is needless

    #include 
    #include 
    #include 
    int main(){ 
           std::vectorv { 1, 7, 1, 3, 6, 7 };
           std::sort( begin(v), end(v) ); // here ADL search finds std::begin, std::end
    }
    

提交回复
热议问题