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

Bas Couwenberg sebastic at debian.org
Mon Oct 24 18:06:58 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 86c5dd1a889639f5c008b1e60230c983963e95d9
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date:   Mon Oct 24 19:07:20 2016 +0200

    Imported Upstream version 1.1.3
---
 Makefile                        |  2 +-
 README.md                       |  3 +-
 include/mapbox/variant.hpp      | 68 ++++++++++++++++++-----------------------
 test/reference_wrapper_test.cpp |  5 ++-
 test/t/issue122.cpp             | 20 ++++++++++++
 5 files changed, 56 insertions(+), 42 deletions(-)

diff --git a/Makefile b/Makefile
index b20f9ee..fc554b8 100644
--- a/Makefile
+++ b/Makefile
@@ -61,7 +61,7 @@ out/%.o: test/t/%.cpp Makefile $(ALL_HEADERS)
 	mkdir -p ./out
 	$(CXX) -c -o $@ $< -Iinclude -Itest/include $(DEBUG_FLAGS) $(COMMON_FLAGS) $(CXXFLAGS)
 
-out/unit: out/unit.o out/binary_visitor_1.o out/binary_visitor_2.o out/binary_visitor_3.o out/binary_visitor_4.o out/binary_visitor_5.o out/binary_visitor_6.o out/issue21.o out/mutating_visitor.o out/optional.o out/recursive_wrapper.o out/sizeof.o out/unary_visitor.o out/variant.o
+out/unit: out/unit.o out/binary_visitor_1.o out/binary_visitor_2.o out/binary_visitor_3.o out/binary_visitor_4.o out/binary_visitor_5.o out/binary_visitor_6.o out/issue21.o out/issue122.o out/mutating_visitor.o out/optional.o out/recursive_wrapper.o out/sizeof.o out/unary_visitor.o out/variant.o
 	mkdir -p ./out
 	$(CXX) -o $@ $^ $(LDFLAGS)
 
diff --git a/README.md b/README.md
index 51b5ec3..1de54de 100644
--- a/README.md
+++ b/README.md
@@ -65,8 +65,7 @@ Tested with:
 
 ## Usage
 
-There is nothing to build, just include `variant.hpp` and
-`recursive_wrapper.hpp` in your project. Include `variant_io.hpp` if you need
+There is nothing to build, just include `variant.hpp` in your project. Include `variant_io.hpp` if you need
 the `operator<<` overload for variant.
 
 
diff --git a/include/mapbox/variant.hpp b/include/mapbox/variant.hpp
index 5b4be3a..afdf36a 100644
--- a/include/mapbox/variant.hpp
+++ b/include/mapbox/variant.hpp
@@ -103,6 +103,26 @@ struct direct_type<T>
     static constexpr std::size_t index = invalid_value;
 };
 
+#if __cpp_lib_logical_traits >= 201510L
+
+using std::disjunction;
+
+#else
+
+template <typename...>
+struct disjunction : std::false_type {};
+
+template <typename B1>
+struct disjunction<B1> : B1 {};
+
+template <typename B1, typename B2>
+struct disjunction<B1, B2> : std::conditional<B1::value, B1, B2>::type {};
+
+template <typename B1, typename... Bs>
+struct disjunction<B1, Bs...> : std::conditional<B1::value, B1, disjunction<Bs...>>::type {};
+
+#endif
+
 template <typename T, typename... Types>
 struct convertible_type;
 
@@ -110,7 +130,7 @@ template <typename T, typename First, typename... Types>
 struct convertible_type<T, First, Types...>
 {
     static constexpr std::size_t index = std::is_convertible<T, First>::value
-        ? sizeof...(Types)
+        ? disjunction<std::is_convertible<T, Types>...>::value ? invalid_value : sizeof...(Types)
         : convertible_type<T, Types...>::index;
 };
 
@@ -120,30 +140,13 @@ 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 : count_convertibles<value_type, Types...>::value == 1
-        ? convertible_type<value_type, Types...>::index : invalid_value;
+    static constexpr std::size_t index = is_direct ? direct_index : convertible_type<value_type, Types...>::index;
     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;
@@ -528,20 +531,6 @@ private:
     Variant const& lhs_;
 };
 
-// True if Predicate matches for all of the types Ts
-template <template <typename> class Predicate, typename... Ts>
-struct static_all_of : std::is_same<std::tuple<std::true_type, typename Predicate<Ts>::type...>,
-                                    std::tuple<typename Predicate<Ts>::type..., std::true_type>>
-{
-};
-
-// True if Predicate matches for none of the types Ts
-template <template <typename> class Predicate, typename... Ts>
-struct static_none_of : std::is_same<std::tuple<std::false_type, typename Predicate<Ts>::type...>,
-                                     std::tuple<typename Predicate<Ts>::type..., std::false_type>>
-{
-};
-
 } // namespace detail
 
 struct no_init
@@ -552,13 +541,16 @@ template <typename... Types>
 class variant
 {
     static_assert(sizeof...(Types) > 0, "Template parameter type list of variant can not be empty");
-    static_assert(detail::static_none_of<std::is_reference, Types...>::value, "Variant can not hold reference types. Maybe use std::reference?");
+    static_assert(!detail::disjunction<std::is_reference<Types>...>::value, "Variant can not hold reference types. Maybe use std::reference_wrapper?");
 
 private:
     static const std::size_t data_size = detail::static_max<sizeof(Types)...>::value;
     static const std::size_t data_align = detail::static_max<alignof(Types)...>::value;
-
-    using first_type = typename std::tuple_element<0, std::tuple<Types...>>::type;
+public:
+    struct adapted_variant_tag;
+    using types = std::tuple<Types...>;
+private:
+    using first_type = typename std::tuple_element<0, types>::type;
     using data_type = typename std::aligned_storage<data_size, data_align>::type;
     using helper_type = detail::variant_helper<Types...>;
 
@@ -578,7 +570,7 @@ public:
 
     // http://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers
     template <typename T, typename Traits = detail::value_traits<T, Types...>,
-              typename Enable = typename std::enable_if<Traits::is_valid>::type>
+              typename Enable = typename std::enable_if<Traits::is_valid && !std::is_same<variant<Types...>, typename Traits::value_type>::value>::type >
     VARIANT_INLINE variant(T&& val) noexcept(std::is_nothrow_constructible<typename Traits::target_type, T&&>::value)
         : type_index(Traits::index)
     {
@@ -591,7 +583,7 @@ public:
         helper_type::copy(old.type_index, &old.data, &data);
     }
 
-    VARIANT_INLINE variant(variant<Types...>&& old) noexcept(std::is_nothrow_move_constructible<std::tuple<Types...>>::value)
+    VARIANT_INLINE variant(variant<Types...>&& old) noexcept(std::is_nothrow_move_constructible<types>::value)
         : type_index(old.type_index)
     {
         helper_type::move(old.type_index, &old.data, &data);
diff --git a/test/reference_wrapper_test.cpp b/test/reference_wrapper_test.cpp
index 18eaecb..3b2085a 100644
--- a/test/reference_wrapper_test.cpp
+++ b/test/reference_wrapper_test.cpp
@@ -41,9 +41,12 @@ struct print
     void operator()(line_string const& line) const
     {
         std::cerr << "Line(";
+        bool first = true;
         for (auto const& pt : line)
         {
-            std::cerr << pt.x << " " << pt.y << ",";
+            if (!first) std::cerr << ",";
+            std::cerr << pt.x << " " << pt.y;
+            if (first) first = false;
         }
         std::cerr << ")" << std::endl;
     }
diff --git a/test/t/issue122.cpp b/test/t/issue122.cpp
new file mode 100644
index 0000000..12de7d5
--- /dev/null
+++ b/test/t/issue122.cpp
@@ -0,0 +1,20 @@
+#include "catch.hpp"
+
+#include <mapbox/variant.hpp>
+#include <mapbox/variant_io.hpp>
+
+// https://github.com/mapbox/variant/issues/122
+
+struct X
+{
+    template <typename ValueType>
+    X(const ValueType&)  {}
+};
+
+
+TEST_CASE("Correctly choose appropriate constructor", "[variant]")
+{
+    mapbox::util::variant<X, int> a{123};
+    decltype(a) b(a);
+    REQUIRE(a.which() == b.which());
+}

-- 
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