// Copyright Toru Niina 2017. // Distributed under the MIT License. #ifndef TOML11_FROM_TOML #define TOML11_FROM_TOML #include "get.hpp" namespace toml { template void from_toml(T& x, const toml::value& v) { x = toml::get::type>(v); return; } namespace detail { template constexpr toml::value_t determine_castable_type() { return check_type() != toml::value_t::Unknown ? check_type() : toml::detail::is_map::value ? toml::value_t::Table : toml::detail::is_container::value ? toml::value_t::Array : toml::value_t::Unknown; } template struct from_toml_tie_impl { constexpr static std::size_t index = sizeof...(Ts) - N; constexpr static toml::value_t type_index = determine_castable_type< typename std::tuple_element>::type>(); static void invoke(std::tuple tie, const toml::value& v) { // static_cast is needed because with intel c++ compiler, operator== // is only defined when the two types are strictly equal, and type_index // is const toml::value_t, while v.type() is toml::value_t. if(static_cast(type_index) == v.type()) { from_toml(std::get(tie), v); return; } return from_toml_tie_impl::invoke(tie, v); } }; template struct from_toml_tie_impl<0, Ts...> { static void invoke(std::tuple tie, const toml::value& v) { return; } }; } // detail template void from_toml(std::tuple tie, const toml::value& v) { detail::from_toml_tie_impl::invoke(tie, v); return; } } // toml #endif // TOML11_FROM_TOML