From cab3144507c30abcb47c3319b7d95e4c52e80ace Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Wed, 19 Jun 2019 16:53:45 +0900 Subject: [PATCH 1/3] style: format CMakelists.txt --- CMakeLists.txt | 40 ++++++++++++++++++++-------------------- tests/CMakeLists.txt | 2 +- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a45686..d359148 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,53 +53,53 @@ set(toml11_config ${toml11_config_dir}/toml11Config.cmake) set(toml11_config_version ${toml11_config_dir}/toml11ConfigVersion.cmake) add_library(toml11 INTERFACE) -target_include_directories(toml11 INTERFACE - $ - $ +target_include_directories(toml11 INTERFACE + $ + $ ) add_library(toml11::toml11 ALIAS toml11) # Write config and version config files include(CMakePackageConfigHelpers) write_basic_package_version_file( - ${toml11_config_version} - VERSION ${toml11_VERSION} - COMPATIBILITY SameMajorVersion + ${toml11_config_version} + VERSION ${toml11_VERSION} + COMPATIBILITY SameMajorVersion ) configure_package_config_file( cmake/toml11Config.cmake.in ${toml11_config} - INSTALL_DESTINATION ${toml11_install_cmake_dir} + INSTALL_DESTINATION ${toml11_install_cmake_dir} PATH_VARS toml11_install_cmake_dir -) +) # Install config files install(FILES ${toml11_config} ${toml11_config_version} - DESTINATION ${toml11_install_cmake_dir} + DESTINATION ${toml11_install_cmake_dir} ) # Install header files install( - FILES toml.hpp - DESTINATION "${toml11_install_include_dir}" + FILES toml.hpp + DESTINATION "${toml11_install_include_dir}" ) install( - DIRECTORY "toml" - DESTINATION "${toml11_install_include_dir}" - FILES_MATCHING PATTERN "*.hpp" + DIRECTORY "toml" + DESTINATION "${toml11_install_include_dir}" + FILES_MATCHING PATTERN "*.hpp" ) # Export targets and install them install(TARGETS toml11 - EXPORT toml11Targets + EXPORT toml11Targets ) -install(EXPORT toml11Targets - FILE toml11Targets.cmake - DESTINATION ${toml11_install_cmake_dir} - NAMESPACE toml11:: +install(EXPORT toml11Targets + FILE toml11Targets.cmake + DESTINATION ${toml11_install_cmake_dir} + NAMESPACE toml11:: ) if (toml11_BUILD_TEST) -add_subdirectory(tests) + add_subdirectory(tests) endif () diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6577085..4dfc912 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -105,4 +105,4 @@ endforeach(TEST_NAME) add_executable(test_multiple_translation_unit test_multiple_translation_unit_1.cpp test_multiple_translation_unit_2.cpp) -target_link_libraries(test_multiple_translation_unit toml11::toml11) +target_link_libraries(test_multiple_translation_unit toml11::toml11) From 24c28c7f4fab70f9ab6f1ebe7a4e66f4da7e100d Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Wed, 19 Jun 2019 18:59:12 +0900 Subject: [PATCH 2/3] fix: correct some SFINAE expressions --- toml/get.hpp | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/toml/get.hpp b/toml/get.hpp index b3bc337..04031f0 100644 --- a/toml/get.hpp +++ b/toml/get.hpp @@ -541,9 +541,12 @@ std::string get_or(const toml::value& v, T&& opt) // others (require type conversion and return type cannot be lvalue reference) template>, - detail::negation>, - detail::negation::type>> + detail::negation::type>::type>>, + detail::negation::type>::type>>, + detail::negation::type>> >::value, std::nullptr_t>::type = nullptr> T get_or(const toml::value& v, T&& opt) { @@ -554,7 +557,7 @@ T get_or(const toml::value& v, T&& opt) } catch(...) { - return opt; + return T(std::move(opt)); } } @@ -639,9 +642,12 @@ std::string find_or(const toml::value& v, const toml::key& ky, T&& opt) // --------------------------------------------------------------------------- // others (require type conversion and return type cannot be lvalue reference) template>, - detail::negation>, - detail::negation::type>> + detail::negation::type>::type>>, + detail::negation::type>::type>>, + detail::negation::type>> >::value, std::nullptr_t>::type = nullptr> T find_or(const toml::value& v, const toml::key& ky, T&& opt) { @@ -651,8 +657,8 @@ T find_or(const toml::value& v, const toml::key& ky, T&& opt) return get_or(tab.at(ky), std::forward(opt)); } -// =========================================================================== -// find_or(table, key, opt) +// --------------------------------------------------------------------------- +// toml::find(table) // --------------------------------------------------------------------------- // exact types (return type can be a reference) @@ -718,9 +724,12 @@ std::string find_or(const toml::table& tab, const toml::key& ky, T&& opt) // --------------------------------------------------------------------------- // others (require type conversion and return type cannot be lvalue reference) template>, - detail::negation>, - detail::negation::type>> + detail::negation::type>::type>>, + detail::negation::type>::type>>, + detail::negation::type>> >::value, std::nullptr_t>::type = nullptr> T find_or(const toml::table& tab, const toml::key& ky, T&& opt) { From 4a2c823d562978eea28743996ea4bcaddb01df53 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Wed, 19 Jun 2019 19:32:25 +0900 Subject: [PATCH 3/3] fix: comparison between values that has a table --- toml/value.hpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/toml/value.hpp b/toml/value.hpp index 84debfb..d7b6e9c 100644 --- a/toml/value.hpp +++ b/toml/value.hpp @@ -1171,6 +1171,9 @@ typename detail::toml_default_type::type&& value::cast() && return detail::switch_cast::invoke(std::move(*this)); } +bool operator==(const toml::value& lhs, const toml::value& rhs); +bool operator< (const toml::value& lhs, const toml::value& rhs); + inline bool operator==(const toml::value& lhs, const toml::value& rhs) { if(lhs.type() != rhs.type()){return false;} @@ -1264,7 +1267,14 @@ inline bool operator<(const toml::value& lhs, const toml::value& rhs) } case value_t::Table : { - return lhs.as_table() < rhs.as_table(); + // since unordered_map does not have `operator<` ... + std::vector> + L(lhs.as_table().begin(), lhs.as_table().end()), + R(rhs.as_table().begin(), rhs.as_table().end()); + std::sort(L.begin(), L.end()); + std::sort(R.begin(), R.end()); + return std::lexicographical_compare( + L.begin(), L.end(), R.begin(), R.end()); } case value_t::Empty : {return false;} case value_t::Unknown : {return false;}