Skip to content

Commit

Permalink
return expected from Builder::build as well
Browse files Browse the repository at this point in the history
Signed-off-by: Mamoru Sobue <[email protected]>
  • Loading branch information
soblin committed Mar 11, 2025
1 parent a68e767 commit 2e5151e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,14 @@ struct InterpolatorMixin : public InterpolatorInterface<T>
}

template <typename... Args>
[[nodiscard]] std::optional<InterpolatorType> build(Args &&... args)
[[nodiscard]] tl::expected<InterpolatorType, interpolator::InterpolationFailure> build(
Args &&... args)
{
auto interpolator = InterpolatorType(std::forward<Args>(args)...);
const interpolator::InterpolationResult success =
interpolator.build(std::move(bases_), std::move(values_));
if (!success) {
return std::nullopt;
return tl::unexpected(success.error());
}
return interpolator;
}
Expand Down
2 changes: 1 addition & 1 deletion common/autoware_trajectory/test/test_interpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TYPED_TEST_SUITE(TestInterpolator, Interpolators, );
TYPED_TEST(TestInterpolator, compute)
{
this->interpolator =
typename TypeParam::Builder().set_bases(this->bases).set_values(this->values).build();
typename TypeParam::Builder().set_bases(this->bases).set_values(this->values).build().value();
for (size_t i = 0; i < this->bases.size(); ++i) {
EXPECT_NEAR(this->values[i], this->interpolator->compute(this->bases[i]), 1e-6);
}
Expand Down

0 comments on commit 2e5151e

Please sign in to comment.