diff options
author | A. Unique TensorFlower <gardener@tensorflow.org> | 2018-04-19 01:56:31 -0700 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2018-04-19 01:59:10 -0700 |
commit | b2536f05bb156612c96f204041ea31980b711fc8 (patch) | |
tree | 322b02696e5efc1ea611c6ce9891056d5e0d352e /tensorflow/core/example | |
parent | d218339e6a05a984ef7b9a49d66db219d862936e (diff) |
Update feature_util's GetFeatures to show compile-time error for unsupported types instead of a link-time error.
PiperOrigin-RevId: 193480683
Diffstat (limited to 'tensorflow/core/example')
-rw-r--r-- | tensorflow/core/example/feature_util.h | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/tensorflow/core/example/feature_util.h b/tensorflow/core/example/feature_util.h index d977935b8a..2265498b5e 100644 --- a/tensorflow/core/example/feature_util.h +++ b/tensorflow/core/example/feature_util.h @@ -182,13 +182,25 @@ struct FeatureTrait< // Returns true if sequence_example has a feature_list with the specified key. bool HasFeatureList(const string& key, const SequenceExample& sequence_example); +template <typename T> +struct TypeHasFeatures : std::false_type {}; + +template <> +struct TypeHasFeatures<Example> : std::true_type {}; + +template <> +struct TypeHasFeatures<Features> : std::true_type {}; + // A family of template functions to return mutable Features proto from a // container proto. Supported ProtoTypes: Example, Features. template <typename ProtoType> -Features* GetFeatures(ProtoType* proto); +typename std::enable_if<TypeHasFeatures<ProtoType>::value, Features*>::type +GetFeatures(ProtoType* proto); template <typename ProtoType> -const Features& GetFeatures(const ProtoType& proto); +typename std::enable_if<TypeHasFeatures<ProtoType>::value, + const Features&>::type +GetFeatures(const ProtoType& proto); // Base declaration of a family of template functions to return a read only // repeated field of feature values. @@ -300,7 +312,7 @@ bool HasFeature(const string& key, const Features& features); template <typename... FeatureType> bool HasFeature(const string& key, const Example& example) { return HasFeature<FeatureType...>(key, GetFeatures(example)); -}; +} // DEPRECATED: use HasFeature instead. // TODO(gorban): update all clients in a followup CL. |