[mapbox-variant] 01/04: Imported Upstream version 1.1.2

Bas Couwenberg sebastic at debian.org
Tue Jul 26 11:37:47 UTC 2016


This is an automated email from the git hooks/post-receive script.

sebastic pushed a commit to branch master
in repository mapbox-variant.

commit ba916393b7aaf318255f3eb5cd3c3d55f5e8eaa3
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date:   Tue Jul 26 13:30:17 2016 +0200

    Imported Upstream version 1.1.2
---
 include/mapbox/variant.hpp | 19 ++++++++++++++++++-
 test/t/issue21.cpp         | 10 ++++++++--
 test/t/variant.cpp         |  2 +-
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/include/mapbox/variant.hpp b/include/mapbox/variant.hpp
index d7c1e86..5b4be3a 100644
--- a/include/mapbox/variant.hpp
+++ b/include/mapbox/variant.hpp
@@ -120,13 +120,30 @@ struct convertible_type<T>
     static constexpr std::size_t index = invalid_value;
 };
 
+
+template <typename T, typename... Types>
+struct count_convertibles;
+
+template <typename T, typename First, typename... Types>
+struct count_convertibles<T, First, Types...>
+{
+    static constexpr std::size_t value = (std::is_convertible<T, First>::value ? 1 : 0) + count_convertibles<T,Types...>::value;
+};
+
+template <typename T>
+struct count_convertibles<T>
+{
+    static constexpr std::size_t value = 0;
+};
+
 template <typename T, typename... Types>
 struct value_traits
 {
     using value_type = typename std::remove_const<typename std::remove_reference<T>::type>::type;
     static constexpr std::size_t direct_index = direct_type<value_type, Types...>::index;
     static constexpr bool is_direct = direct_index != invalid_value;
-    static constexpr std::size_t index = is_direct ? direct_index : convertible_type<value_type, Types...>::index;
+    static constexpr std::size_t index = is_direct ? direct_index : count_convertibles<value_type, Types...>::value == 1
+        ? convertible_type<value_type, Types...>::index : invalid_value;
     static constexpr bool is_valid = index != invalid_value;
     static constexpr std::size_t tindex = is_valid ? sizeof...(Types)-index : 0;
     using target_type = typename std::tuple_element<tindex, std::tuple<void, Types...>>::type;
diff --git a/test/t/issue21.cpp b/test/t/issue21.cpp
index e979027..a33d359 100644
--- a/test/t/issue21.cpp
+++ b/test/t/issue21.cpp
@@ -1,4 +1,3 @@
-
 #include "catch.hpp"
 
 #include <mapbox/variant.hpp>
@@ -11,6 +10,12 @@ static int count;
 struct t1
 {
     int value;
+
+    t1(t1 const& rhs)
+        : value(rhs.value)
+    {
+        ++count;
+    }
     t1(int v) : value(v)
     {
         ++count;
@@ -37,7 +42,8 @@ TEST_CASE("set() works cleanly even if the constructor throws ", "[variant]")
 
     count = 0;
     {
-        variant_type v{42};
+        t1 obj{42};
+        variant_type v = obj;
         REQUIRE(v.is<t1>());
         REQUIRE(v.get<t1>().value == 42);
         REQUIRE_THROWS({
diff --git a/test/t/variant.cpp b/test/t/variant.cpp
index a192269..b4322a2 100644
--- a/test/t/variant.cpp
+++ b/test/t/variant.cpp
@@ -325,7 +325,7 @@ TEST_CASE("implicit conversion", "[variant][implicit conversion]")
 TEST_CASE("implicit conversion to first type in variant type list", "[variant][implicit conversion]")
 {
     using variant_type = mapbox::util::variant<long, char>;
-    variant_type var = 5.0; // converted to long
+    variant_type var = 5l; // converted to long
     REQUIRE(var.get<long>() == 5);
     REQUIRE_THROWS_AS({
         var.get<char>();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/mapbox-variant.git



More information about the Pkg-grass-devel mailing list