Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 1724: operator() - funny refactoring suggestion

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
tandr Posted - May 27 2009 : 5:46:49 PM
C++, VS2008 SP1 + hotfixes


class Funny
{
    bool operator()(int param1, int param2)
    {
        // PART ONE
       if (param1 < 0)
            return false;
        else if (param1 == 0)
            throw Funny;
        else
            return true;
       // END PART ONE

        if (param2 < 0)
            return false;
        else if (param2 == 0)
            throw Funny;
        else
            return true;
    }
};


If you select what is enclosed between PART ONE and END OF PART ONE markers, and choose Refactor(VAX)->Extract method, it will make very strange name suggestion, like it could not extract correct type out of operator() and just takes whole thing as type. Which is double strange, since the return type should be dictated by what selected, not the old whole function.

[light bitching mode]
The whole operator() business is a bit of disappointment with VAX. For example, in order to get to implementation of bool operator()(), you absolutely HAVE to place caret in between braces pair "()|()" or just after word operator "operator|()()", otherwise it does not even bother to react to alt-g. Second, (and probably related) - to find all references to the operator() is impossible, it asks "place caret to the symbol before running Find References".
[/light bitching mode]

operator() become quite a popular in C++ in the recent years, so I keep my fingers crossed for VAX to have it fixed.

Thank you very much,
t.

My info:

VA_X.dll file version 10.5.1724.0 built 2009.05.01
Licensed to:
VA X: [email protected] (1-user license) Support ends 2010.02.04
DevEnv.exe version 9.0.30729.1
msenv.dll version 9.0.30729.1
Font: Consolas 11(Pixels)
Comctl32.dll version 6.0.2900.5512
Windows XP 5.1 Build 2600 S
2 processors (x86)

Platform: Win32
Stable Includes:
D:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\include;
D:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\atlmfc\\include;
D:\\Program Files\\Microsoft SDKs\\Windows\\v6.1\\include;
D:\\Program Files\\Microsoft SDKs\\Windows\\v6.1\\include;
E:\\repos\\3rd\\boost\\tags\\Boost_1_39_0;

Other Includes:

Stable Source Directories:
D:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\atlmfc\\src\\mfc;
D:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\atlmfc\\src\\mfcm;
D:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\atlmfc\\src\\atl;
D:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\crt\\src;


4   L A T E S T    R E P L I E S    (Newest First)
sean Posted - Jun 12 2009 : 9:24:24 PM
case=27615 is fixed in build 1727
feline Posted - May 31 2009 : 5:18:12 PM
Thank you for the link, I am not familiar with that technique. I am surprised it even compiles, since I am not used to seeing a template function called like that. Live and learn
drac Posted - May 30 2009 : 12:12:44 PM
operator() is used in function objects (functors), very popular with STL code.

Wikipedia has a good description http://en.wikipedia.org/wiki/Function_object

feline Posted - May 29 2009 : 1:02:58 PM
Extract Method, I am seeing the same effect here. Thank you for the clear description.

case=27615


The rest of your points, I have never heard of overloading (), and I have worked in C and C++ for years. So it may be common, but this is the first time I have ever heard of it. A quick search finally threw up this page:

http://www.parashift.com/c++-faq-lite/operator-overloading.html

which does a good job of explaining what this is all about.

I suspect our parser is not really familiar with this idea either.

Triggering refactoring, with the function declaration:

bool oper|ator()(int nOne, int nTwo);

if I place the caret into the keyword operator as shown VA is quite happy to offer me both Create Implementation and Document Method.

As for Find References, that is a scary thought. Trying to reliably run Find References on overloaded operators, casting operators, etc, just throws up so many edge cases... I suspect some of the edge cases can only be resolved at run time, not even at compile time.

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000