Fabric: Universal `fromDynamic` for `std::vector<...>`

Summary:
Now, if `fromDynamic` is defined for some type, `fromDynamic` for `std::vector` of this type is also will be defined.
We need this for parsing `ImageSources` (a vector of `ImageSource`) type.

Reviewed By: fkgozali

Differential Revision: D8473508

fbshipit-source-id: d8dc8e3a3273f35b76c7132c553130762f768394
This commit is contained in:
Valentin Shergin 2018-06-17 21:36:02 -07:00 committed by Facebook Github Bot
parent d92601be05
commit 310a2850c5
1 changed files with 10 additions and 0 deletions

View File

@ -24,6 +24,16 @@ inline void fromDynamic(const folly::dynamic &value, int &result) {
}
inline void fromDynamic(const folly::dynamic &value, std::string &result) { result = value.getString(); }
template <typename T>
inline void fromDynamic(const folly::dynamic &value, std::vector<T> &result) {
result.clear();
T itemResult;
for (auto &itemValue : value) {
fromDynamic(itemValue, itemResult);
result.push_back(itemResult);
}
}
template <typename T>
inline T convertRawProp(
const RawProps &rawProps,