Commit 87de301d authored by Yong Tang's avatar Yong Tang Committed by drpngx
Browse files

Add templated functions for `safe_strto[f|d|i32|i64|u32|u64]` (#14789)



* Add templated functions for `safe_strto[f|d|i32|i64|u32|u64]`

While working on 14330 I noticed that there is no templated functions for
`safe_strto[f|d|i32|i64|u32|u64]`. As a result, an additional wrapper
has to be created in different places to apply the typename in a
templated class or function. Examples include the existing implementations
in `tensorflow/core/kernels/string_to_number_op.cc` (`Convert`),
`tensorflow/core/lib/strings/proto_text_util.h` (`ProtoParseNumeric`),
and in 14330.
It might make sense to add a templated function for `safe_strto[f|d|i32|i64|u32|u64]`
to avoid existing and future code duplications.
This fix adds
```
template<typename T>
bool SafeStringToNumeric(StringPiece s, T* value);
```
to address the above mentioned issue.

Signed-off-by: default avatarYong Tang <yong.tang.github@outlook.com>

* Move ProtoParseNumeric to numbers.h, and use overloading in template

Signed-off-by: default avatarYong Tang <yong.tang.github@outlook.com>
parent c1d9f867
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment