Skip to content

Commit

Permalink
Fix jmespath_custom_function_example, use ref
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Dec 10, 2024
1 parent 54e57c3 commit ba2c43a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions examples/src/jmespath_custom_function_examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class my_custom_functions : public jmespath::custom_functions<Json>
return resources.null_value();
}

const auto context = params[0].value();
const auto& context = params[0].value();
const auto countValue = get_value(context, resources, params[1]);
const auto& expr = params[2].expression();
const auto& argDefault = params[3];
Expand All @@ -114,7 +114,8 @@ class my_custom_functions : public jmespath::custom_functions<Json>
current_index = i;
std::error_code ec2;

auto ele = expr.evaluate(context, resources, ec2);
const auto& ele = expr.evaluate(context, resources, ec2); // must be reference
std::cout << ec2.message() << "\n";

if (ele.is_null())
{
Expand All @@ -123,8 +124,8 @@ class my_custom_functions : public jmespath::custom_functions<Json>
}
else
{
// result->emplace_back(ele); // ?: It may lead to an abnormal exit.
result->emplace_back(*resources.create_json(deep_copy(ele)));
result->emplace_back(ele); // okay if context is a reference
//result->emplace_back(*resources.create_json(deep_copy(ele)));
}
}
current_index = 0;
Expand Down

0 comments on commit ba2c43a

Please sign in to comment.