Hacker News new | past | comments | ask | show | jobs | submit login

IIRC, importing an entire namespace into scope is a feature that was added exclusively for backwards compatibility and is not idiomatic modern C++.

What is idiomatic is explicitly importing individual symbols into a name peace.

    #include <iostream>
    #include <vector>
    #include <string>
    
    using std::cout;
    using std::vector;
    using std::string;

    int main() { 
    
      vector<string> v {"explicit ", "is better ", "than implicit\n" };

      for (auto p: v) cout << p;
      
      return 0;
      
    }
I'm on mobile so please forgive errors.



Wow, I never knew about that. I always hated having std:: everywhere, just so I could have "correct" C++. But I also hated referencing to std implicitly. This is the perfect tradeoff: explicitly state intentions in the beginning, then implicitly reference them as you go. (works until you use eighty five billion lines just to import your symbols)




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: