From b6e2c6e235b18fcf581ff376363b273e789050f4 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Fri, 14 May 2021 15:46:00 +0900 Subject: [PATCH 1/7] feat: add detail::has_specialization_from/into --- toml/traits.hpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/toml/traits.hpp b/toml/traits.hpp index eafa6af..209856d 100644 --- a/toml/traits.hpp +++ b/toml/traits.hpp @@ -2,6 +2,10 @@ // Distributed under the MIT License. #ifndef TOML11_TRAITS_HPP #define TOML11_TRAITS_HPP + +#include "from.hpp" +#include "into.hpp" + #include #include #include @@ -84,6 +88,22 @@ struct has_into_toml_method_impl static std::false_type check(...); }; +struct has_specialized_from_impl +{ + template + static std::false_type check(...); + template + static std::true_type check(std::nullptr_t, std::size_t S = sizeof(::toml::from)); +}; +struct has_specialized_into_impl +{ + template + static std::false_type check(...); + template + static std::true_type check(std::nullptr_t, std::size_t S = sizeof(::toml::into)); +}; + + /// Intel C++ compiler can not use decltype in parent class declaration, here /// is a hack to work around it. https://stackoverflow.com/a/23953090/4692076 #ifdef __INTEL_COMPILER @@ -114,6 +134,11 @@ template struct has_into_toml_method : decltype(has_into_toml_method_impl::check(nullptr)){}; +template +struct has_specialized_from : decltype(has_specialized_from_impl::check(nullptr)){}; +template +struct has_specialized_into : decltype(has_specialized_into_impl::check(nullptr)){}; + #ifdef __INTEL_COMPILER #undef decltype #endif From 72ee8caf09ba7a6d79827614611ddd20001cf4b0 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Fri, 14 May 2021 15:53:34 +0900 Subject: [PATCH 2/7] refactor: use has_specialized_from to check if toml::from exists for a specific T --- toml/get.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/toml/get.hpp b/toml/get.hpp index 5095caf..9a5a855 100644 --- a/toml/get.hpp +++ b/toml/get.hpp @@ -255,9 +255,9 @@ get(const basic_value&); // toml::from::from_toml(v) template class M, template class V, - std::size_t S = sizeof(::toml::from)> -T get(const basic_value&); + template class M, template class V> +detail::enable_if_t::value, T> +get(const basic_value&); // T(const toml::value&) and T is not toml::basic_value template& v) return ud; } template class M, template class V, - std::size_t> -T get(const basic_value& v) + template class M, template class V> +detail::enable_if_t::value, T> +get(const basic_value& v) { return ::toml::from::from_toml(v); } From e62259542662551b1a67bebc5823fda3373423c4 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Fri, 14 May 2021 16:01:43 +0900 Subject: [PATCH 3/7] fix: fix has_specialized_from/into to avoid ambiguity --- toml/traits.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/toml/traits.hpp b/toml/traits.hpp index 209856d..0064e37 100644 --- a/toml/traits.hpp +++ b/toml/traits.hpp @@ -92,15 +92,15 @@ struct has_specialized_from_impl { template static std::false_type check(...); - template - static std::true_type check(std::nullptr_t, std::size_t S = sizeof(::toml::from)); + template)> + static std::true_type check(::toml::from*); }; struct has_specialized_into_impl { template static std::false_type check(...); - template - static std::true_type check(std::nullptr_t, std::size_t S = sizeof(::toml::into)); + template)> + static std::true_type check(::toml::from*); }; From 0ac3919e084307e2c6be0d1a549830cfe19aed31 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Fri, 14 May 2021 16:05:54 +0900 Subject: [PATCH 4/7] feat: from and from_toml precede constructor constructor sometimes has `template ctor(const T&)` and it causes ambiguity. To avoid it, from and T.from_toml precedes any constructor. But, to check the ambiguity between from and from_toml, they do not precede each other. If anyone define both from and from_toml, it causes compilation error. --- toml/get.hpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/toml/get.hpp b/toml/get.hpp index 9a5a855..a766f4a 100644 --- a/toml/get.hpp +++ b/toml/get.hpp @@ -259,12 +259,15 @@ template::value, T> get(const basic_value&); -// T(const toml::value&) and T is not toml::basic_value +// T(const toml::value&) and T is not toml::basic_value, +// and it does not have `from` nor `from_toml`. template class M, template class V> detail::enable_if_t>, - std::is_constructible&> + std::is_constructible&>, + detail::negation>, + detail::negation> >::value, T> get(const basic_value&); @@ -450,8 +453,10 @@ get(const basic_value& v) template class M, template class V> detail::enable_if_t>, - std::is_constructible&> + detail::negation>, // T is not a toml::value + std::is_constructible&>, // T is constructible from toml::value + detail::negation>, // and T does not have T.from_toml(v); + detail::negation> // and T does not have toml::from{}; >::value, T> get(const basic_value& v) { From 07c1d10212720e22de499429d8254ddd0fb08d9d Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Fri, 14 May 2021 16:16:23 +0900 Subject: [PATCH 5/7] ci: avoid clang-9 + C++20 because it lacks <=> And the operator<=> is used in the (GNU-) standard library implementation installed by default. Note: consider using libc++ library --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 04ab80b..874886b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -59,6 +59,7 @@ jobs: - {compiler: '6.0', standard: '20'} - {compiler: '7', standard: '20'} - {compiler: '8', standard: '20'} + - {compiler: '9', standard: '20'} steps: - name: Checkout uses: actions/checkout@v2 From 798856946f0c58f8cc7272d0f63769e10d904d96 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Fri, 14 May 2021 18:19:44 +0900 Subject: [PATCH 6/7] ci: add new compilers gcc 10, 11, clang 11 --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 874886b..9f31914 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: # g++-4.8 and 4.9 are tested on Travis.CI. - compiler: ['g++-9', 'g++-8', 'g++-7', 'g++-6', 'g++-5'] + compiler: ['g++-11', 'g++-10', 'g++-9', 'g++-8', 'g++-7', 'g++-6', 'g++-5'] standard: ['11', '14', '17', '20'] exclude: - {compiler: 'g++-5', standard: '17'} @@ -47,7 +47,7 @@ jobs: runs-on: Ubuntu-18.04 strategy: matrix: - compiler: ['10', '9', '8', '7', '6.0', '5.0', '4.0', '3.9'] + compiler: ['11', '10', '9', '8', '7', '6.0', '5.0', '4.0', '3.9'] standard: ['11', '14', '17', '20'] exclude: - {compiler: '3.9', standard: '17'} From 287be5a5757676c44c73900542d76617acad439b Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Fri, 14 May 2021 18:25:29 +0900 Subject: [PATCH 7/7] ci: clang11 is too new to install it without adding a new ppa --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9f31914..2a20744 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -47,7 +47,7 @@ jobs: runs-on: Ubuntu-18.04 strategy: matrix: - compiler: ['11', '10', '9', '8', '7', '6.0', '5.0', '4.0', '3.9'] + compiler: ['10', '9', '8', '7', '6.0', '5.0', '4.0', '3.9'] standard: ['11', '14', '17', '20'] exclude: - {compiler: '3.9', standard: '17'}