* ARG_TYPE_1 *arg1;
* ARG_TYPE_2 *arg2;
*
- * bool ok = commutative_args_of(node).is(arg1, arg2);
+ * bool ok = fill(&arg1, &arg2).with_commutative_args_of(node);
*
* Result
* If 'node's commutative argument types are actually {ARG_TYPE_1, ARG_TYPE_2}
* Otherwise, 'arg1' and 'arg2' not changed, 'ok' is false.
*/
-/// @require COMM_NODE has member x() and y()
-template <class COMM_NODE> class CommutativeArgsGetter final
-{
-public:
- CommutativeArgsGetter(COMM_NODE *node) : _node(node)
- {
- assert(node);
- assert(node->arity() == 2);
- assert(node->x());
- assert(node->y());
- }
-
-public:
- /**
- * @note This function might make change to arguments
- *
- * @param[out] arg_* These would be set to actual argument node pointer on check success
- *
- * @return true When '_node's argument types are 'ARG_TYPE_1' and 'ARG_TYPE_2'
- * In such case, it assign 'arg_1' and 'arg_2' to actual arguments
- *
- * @return false When '_node's argument types are NOT matched with 'ARG_TYPE_*'
- * In such case, it does not amend 'arg_1' and 'arg_2'
- */
- template <class ARG_TYPE_1, class ARG_TYPE_2> bool is(ARG_TYPE_1 *&arg_1, ARG_TYPE_2 *&arg_2);
-
-private:
- COMM_NODE *_node = nullptr;
-};
-
-template <class COMM_NODE>
-inline CommutativeArgsGetter<COMM_NODE> commutative_args_of(COMM_NODE *node)
-{
- return CommutativeArgsGetter<COMM_NODE>{node};
-}
-
-template <class COMM_NODE>
-template <class ARG_TYPE_1, class ARG_TYPE_2>
-bool CommutativeArgsGetter<COMM_NODE>::is(ARG_TYPE_1 *&arg_1, ARG_TYPE_2 *&arg_2)
-{
- // Case 1) X == ARG_TYPE_1 / Y == ARG_TYPE_2
- {
- auto x = dynamic_cast<ARG_TYPE_1 *>(_node->x());
- auto y = dynamic_cast<ARG_TYPE_2 *>(_node->y());
-
- if (x && y)
- {
- arg_1 = x;
- arg_2 = y;
- return true;
- }
- }
-
- // Case 2) X == ARG_TYPE_2 / Y == ARG_TYPE_1
- {
- auto x = dynamic_cast<ARG_TYPE_2 *>(_node->x());
- auto y = dynamic_cast<ARG_TYPE_1 *>(_node->y());
-
- if (x && y)
- {
- arg_1 = y;
- arg_2 = x;
- return true;
- }
- }
-
- return false;
-}
-
-/**
- * Alternative approach
- *
- * bool ok = fill(&arg1, &arg2).with_commutative_args_of(node);
- */
-
template <class ARG_TYPE_1, class ARG_TYPE_2> class NodeFiller final
{
public: