Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Feature Requests
 refactor help with adding/using namespaces
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

peterchen
Tomato Guru

126 Posts

Posted - Sep 26 2014 :  08:40:31 AM  Show Profile  Reply with Quote
given

// bar.h
namespace Foo
{
   struct Bar {}
}

// bar.cpp
Bar b;

The refactor menu for Bar (in bar.cpp) offers to "include bar.h". This usually works well.

However, it does not help with adding the required namespace.

The following suggestions would be nice:

  • add "Foo::" to the declaration (resulting in Foo::Bar b;)

  • add "using namespace Foo" to current scope, current function or current file

  • add "using Foo::Bar" to one of these scopes


Thinking about it, there are pretty many options how to resolve this, I'm not quite sure how to present them, maybe "add to current scope" is not that very and could be omitted.

Of course, "using namespace..." should not be suggested in a header file, and "add to current scope" can be omitted if the current scope is the function (or file).

Edited by - peterchen on Sep 26 2014 08:44:41 AM

feline
Whole Tomato Software

United Kingdom
19021 Posts

Posted - Sep 26 2014 :  3:18:00 PM  Show Profile  Reply with Quote
Which method do you tend to use in your code? From the code samples I see, adding "using namespace Foo" to the file, so effecting the entire file, seems a fairly common method. This has the advantage of giving you a using statement you can easily cut and paste if you want to place it somewhere else, narrowing its scope.

zen is the art of being at one with the two'ness
Go to Top of Page

peterchen
Tomato Guru

126 Posts

Posted - Sep 30 2014 :  09:59:05 AM  Show Profile  Reply with Quote
I would probably opt for "function level" most of the time - I personally find that preferrable if only only one or two functions (out of dozens) are affected.

At file level if the majority of functions would have that using statement, e.g. a UI class pulling in UI ultilities.

Anyway, even with "using statement at file level" and "change declaration to include namespace", this would be a very valuable feature - changing the using statement to be more local is a bit rote but easy to do.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19021 Posts

Posted - Oct 08 2014 :  7:11:04 PM  Show Profile  Reply with Quote
Apologies for the slow reply. This makes sense, and adding a using namespace line to help where required is something we are considering, so I have added the thoughts from here to the case:

case=32045

zen is the art of being at one with the two'ness
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000