How to find move constructors in codebase using grep or an IDE?
c++, move-constructor
Solution
Looks like a job for regular expressions. In Visual Studio, press ctrl+F. In the search pop-up window, activate the option "Use regular expressions" (or press alt+E, when the search line is active). Then type the following expression:
\b\w+\s*[\(]\s*(const)*\s*(volatile)*\s*\w+\s*[&][&]\s*[\)]
It will find any string of the form:
class_name(class_name&&)
class_name(const class_name&&)
class_name(volatile class_name&&)
class_name(const volatile class_name&&)
as specified in:
http://en.cppreference.com/w/cpp/language/move_constructor
The expression works also if there is any number of whitespaces between class_name, parentheses and keywords like const etc.
If you want it to work also for named variables, e.g.:
class_name(class_name&& variable_name)
it's enough to modify it slightly:
\b(\w+)\s*[\(]\s*(const)*\s*(volatile)*\s*\1\s*[&][&]\s*\w*\s*[\)]
EDIT: As an answer to the OP's request, I've modified the above regex in such a way that it uses backreference now. The '\1' means "Find the same expression that was captured by the first expression grouped in parentheses" - the first such expression is (\w+), which is the first 'class_name' in the examplary move constructors above. This ensures that there is the same string on both sides of this guy: '('. To sum it up: one additional pair of parentheses, '\1' and magic happens.
Interesting thing is that Microsoft doesn't mention that VS supports backreferences.
More information about regular expressions in Visual Studio can be found here:
http://msdn.microsoft.com/en-us/library/2k3te2cs.aspx
Problem
I want to find move constructors in codebase of a large c++ project. Simply grepping for "&&" doesn't work, because it matches a lot of 'logical and' operators. Any way to grep more precisely for move constructors? Any way to search for move constructors using Visual Studio (on Windows) or XCode (on Mac)?