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:Yong Tang <yong.tang.github@outlook.com> * Move ProtoParseNumeric to numbers.h, and use overloading in template Signed-off-by:
Yong Tang <yong.tang.github@outlook.com>
Loading
Please sign in to comment