Skip to content

Commit

Permalink
Handle unsupported result types when casting strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
saminbassiri committed Oct 1, 2024
1 parent 6635a57 commit 5205b56
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/runtime/local/kernels/CastSca.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ struct CastSca<VTRes, std::string> {

else if constexpr(std::is_same<VTRes, float>::value)
return static_cast<VTRes>(std::stof(arg));
else {
// Trigger a compiler warning using deprecated attribute
return unsupported_type(arg);
}
}

[[deprecated("CastSca: Warning! Unsupported result type in casting string values.")]]
static VTRes unsupported_type(std::string arg) {
throw std::runtime_error("CastSca: Unsupported result type in casting string values");
}
};

Expand All @@ -100,6 +109,15 @@ struct CastSca<VTRes, FixedStr16> {

else if constexpr(std::is_same<VTRes, float>::value)
return static_cast<VTRes>(std::stof(arg.buffer));
else {
// Trigger a compiler warning using deprecated attribute
return unsupported_type(arg);
}
}

[[deprecated("CastSca: Warning! Unsupported result type in casting string values.")]]
static VTRes unsupported_type(std::string arg) {
throw std::runtime_error("CastSca: Unsupported result type in casting string values");
}
};

Expand Down

0 comments on commit 5205b56

Please sign in to comment.