Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect usage of std:: and avoid using namespace #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

m42e
Copy link

@m42e m42e commented Dec 17, 2015

E.g. goole code style tells you not to do so.

@quark-zju
Copy link
Owner

To be honest, the current change makes the code harder to read. $1 is discouraged in Ruby and names like regexp and rex confuses people.

Let's do this instead: If std:: is found, do not add using namespace std;

diff --git a/cpp_auto_include.vim b/cpp_auto_include.vim
index 6bcfa34..e593250 100644
--- a/cpp_auto_include.vim
+++ b/cpp_auto_include.vim
@@ -111,6 +111,7 @@ module CppAutoInclude
   ]

   USING_STD       = 'using namespace std;'
+  USING_STD_REGEX = /using namespace std;|std::/

   # do nothing if lines.count > LINES_THRESHOLD
   LINES_THRESHOLD = 1000
@@ -164,7 +165,7 @@ module CppAutoInclude
         end

         # add / remove 'using namespace std'
-        has_std = content[USING_STD]
+        has_std = content[USING_STD_REGEX]

         if use_std && !has_std && !includes.empty?
           VIM::append(includes.last.last+1, USING_STD) 

@m42e
Copy link
Author

m42e commented Dec 17, 2015

Ok, i haven't thought about that Solution. Well to be honest I haven't really taken care of the variable names. Thanks.

Am 17.12.2015 um 22:31 schrieb Jun Wu <[email protected] mailto:[email protected] >:

To be honest, the current change make the code hard to read. $1 is discouraged in Ruby and names like regexp and rex confuses people.

Let's do this instead: If std:: is found, do not add using namespace std;

diff --git a/cpp_auto_include.vim b/cpp_auto_include.vim
index 6bcfa34..e593250 100644
--- a/cpp_auto_include.vim
+++ b/cpp_auto_include.vim
@@ -111,6 +111,7 @@ module CppAutoInclude
]

USING_STD = 'using namespace std;'

  • USING_STD_REGEX = /using namespace std;|std::/

do nothing if lines.count > LINES_THRESHOLD

LINES_THRESHOLD = 1000
@@ -164,7 +165,7 @@ module CppAutoInclude
end

 # add / remove 'using namespace std'
  •    has_std = content[USING_STD]
    
  •    has_std = content[USING_STD_REGEX]
    
     if use_std && !has_std && !includes.empty?
       VIM::append(includes.last.last+1, USING_STD) 
    


Reply to this email directly or view it on GitHub.

@m42e m42e force-pushed the no_using_namespace branch from f52997f to 54efbe5 Compare December 18, 2015 06:52
@m42e
Copy link
Author

m42e commented Dec 21, 2015

Fixed it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants