From b8d3038d383a4caf93df054badf70181f4e8447c Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sat, 1 Jun 2019 16:03:26 +0900 Subject: [PATCH] feat: add meta function to detect conversions --- toml/types.hpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/toml/types.hpp b/toml/types.hpp index f15e955..2c0d9d8 100644 --- a/toml/types.hpp +++ b/toml/types.hpp @@ -139,6 +139,59 @@ template struct is_exact_toml_type template struct is_exact_toml_type : is_exact_toml_type{}; template struct is_exact_toml_type: is_exact_toml_type{}; +// meta-function that check type T is convertible to toml::* types +template +struct is_convertible_to_toml_value : disjunction< + std::is_same, // T is bool or + std::is_integral, // T is an integer or + std::is_floating_point, // T is a floating point or + std::is_same, // T is std::string or + std::is_same, // T is toml::string or + is_string_literal, // T is "string literal" or + std::is_same, // T is local_date or + std::is_same, // T is local_time or + std::is_same, // T is local_datetime or + std::is_same, // T is offset_datetime or + std::is_same // T is time_point or + is_chrono_duration, // T is a duration or + std::is_same, // T is an array type or + std::is_same, // T is an array type or + >{} + +// meta-function that returns value_t that represent the convertible type +template +struct convertible_toml_type_of : typename std::conditional< + /* if */ is_exact_toml_type::value, + /* then */ value_t_constant::value>, + /* else */ typename std::conditional< + // ---------------------------------------------------------------------- + /* if */ std::is_integral::value, + /* then */ value_t_constant, + /* else */ typename std::conditional< + // ---------------------------------------------------------------------- + /* if */ std::is_floating_point::value, + /* then */ value_t_constant, + /* else */ typename std::conditional< + // ---------------------------------------------------------------------- + /* if */ std::is_same::value, + /* then */ value_t_constant, + /* else */ typename std::conditional< + // ---------------------------------------------------------------------- + /* if */ is_string_literal, + /* then */ value_t_constant, + /* else */ typename std::conditional< + // ---------------------------------------------------------------------- + /* if */ is_chrono_duration, + /* then */ value_t_constant, + /* else */ typename std::conditional< + // ---------------------------------------------------------------------- + /* if */ std::is_same, + /* then */ value_t_constant, + /* else */ value_t_constant, + // ---------------------------------------------------------------------- + >::type>::type>::type>::type>::type>::type>::type + >{} + } // detail } // toml #endif// TOML11_TYPES_H