- The push function was replaced with the emplace function defined as a template member function to forward the arguments to the stack emplace function (see details below).
- The pop function was replaced with the pop string function with basically does the same thing except is not longer checks if the stack is empty (which was only needed during initial development of the recreator).
- The top function was replaced with individual functions for returning the precedence and unary operator flag members of the top stack item. No similar function was added for the string member as there are other functions for accessing the string member: pop string, top append, and new top add parentheses.
- A new top add parentheses function was added to add parentheses around the string of the top stack item. This function is only called by the parentheses recreate function.
- The precedence and unary operator pointer arguments were removed from the pop with parentheses function since they were only used by the parentheses recreate function (which now has its own access function).
- The stack is empty function was renamed to just empty to be consistent with the other stack access functions (which don't have the stack name included) and with the STL naming convention.
template <typename... Args>This utilizes the new C++11 perfect forwarding feature, allowing a function template to pass its arguments through to another function and avoids unnecessary copying. What the above template does is pass the stack item constructor arguments to the stack emplace function (using the std::forward template function), which are then passed to the stack item constructor when the new item is created on the stack, without copying the arguments.
void emplace(Args&&... args) {
m_stack.emplace(std::forward<Args>(args)...);
}
To use the emplace stack function, a constructor was added to the stack item structure. The constructor has arguments for each of the three member variables. The precedence and unary operator arguments were made optional with defaults (from the replaced push function). The member variables of the stack item were also renamed with the "m_" prefix.
[branch recreator commit 5451552470]
No comments:
Post a Comment
All comments and feedback welcomed, whether positive or negative.
(Anonymous comments are allowed, but comments with URL links or unrelated comments will be removed.)