Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <array>
- #include <functional>
- #include <string>
- #include <any>
- // dummy
- template<typename T>
- T GetValueByKey(const char* key)
- {
- return T(0);
- }
- template<>
- int GetValueByKey(const char* key)
- {
- return 10;
- }
- template<>
- long GetValueByKey(const char* key)
- {
- return 15L;
- }
- template<>
- std::string GetValueByKey(const char* key)
- {
- return "aaa";
- }
- template <size_t Idx, typename ... JoinType>
- void FindJoinValue(std::tuple<JoinType...> &res, const std::array<const char *, sizeof ... (JoinType)> &keys)
- {
- constexpr size_t VarSize = sizeof ... (JoinType);
- using KeyType = std::remove_cv_t<std::remove_reference_t<decltype(std::get<Idx>(res))>>;
- KeyType x = GetValueByKey<KeyType>(keys[Idx]);
- std::get<Idx>(res) = x;
- if constexpr (Idx != 0)
- FindJoinValue<Idx - 1, JoinType...>(res, keys);
- }
- template <typename ... JoinType>
- void FindJoinValue(const std::array<const char *, sizeof ... (JoinType)> &keys/*, std::function<bool(std::tuple<JoinType...>)> c*/)
- {
- constexpr size_t VarSize = sizeof ... (JoinType);
- std::tuple<JoinType...> res;
- FindJoinValue<VarSize - 1, JoinType...>(res, keys);
- //c(res);
- }
- int main(int argc, char** argv)
- {
- std::array<const char*, 3> arr{ "Hey", "Hi", "Hello" };
- FindJoinValue<int, long, std::string>(arr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement