From 75ffdba9a3e6b8d1da492651b89971ff70a44dc9 Mon Sep 17 00:00:00 2001 From: Sergey Lyskov Date: Mon, 9 May 2016 15:57:35 -0400 Subject: [PATCH] Adding workarounds for MSVC 2015 --- include/pybind11/stl_binders.h | 44 ++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/include/pybind11/stl_binders.h b/include/pybind11/stl_binders.h index e5ec700e6..7fcf635a7 100644 --- a/include/pybind11/stl_binders.h +++ b/include/pybind11/stl_binders.h @@ -21,16 +21,18 @@ NAMESPACE_BEGIN(pybind11) -#if (!defined _MSC_VER) || (_MSC_VER > 1900) - #define INSERTION_OPERATOR_IMPLEMENTATION -#endif - template constexpr auto has_equal_operator(int) -> decltype(std::declval() == std::declval(), bool()) { return true; } template constexpr bool has_equal_operator(...) { return false; } +// Workaround for MSVC 2015 +template +struct has_equal_operator_s { + static const bool value = has_equal_operator(0); +}; + template @@ -38,8 +40,13 @@ constexpr auto has_not_equal_operator(int) -> decltype(std::declval() != std: template constexpr bool has_not_equal_operator(...) { return false; } +// Workaround for MSVC 2015 +template +struct has_not_equal_operator_s { + static const bool value = has_not_equal_operator(0); +}; + -#ifdef INSERTION_OPERATOR_IMPLEMENTATION namespace has_insertion_operator_implementation { enum class False {}; struct any_type { @@ -52,7 +59,13 @@ constexpr bool has_insertion_operator() { using namespace has_insertion_operator_implementation; return std::is_same< decltype(std::declval() << std::declval()), std::ostream & >::value; } -#endif + +// Workaround for MSVC 2015 +template +struct has_insertion_operator_s { + static const bool value = has_insertion_operator(); +}; + template , typename holder_type = std::unique_ptr< std::vector > > @@ -98,7 +111,7 @@ class vector_binder { void maybe_copy_constructible() {} - template(0) >::type * = nullptr> + template::value >::type * = nullptr> void maybe_has_equal_operator() { cl.def(pybind11::self == pybind11::self); cl.def(pybind11::self != pybind11::self); @@ -113,25 +126,24 @@ class vector_binder { cl.def("__contains__", [](Vector const &v, T const &t) { return std::find(v.begin(), v.end(), t) != v.end(); }, "return true if item in the container"); } - template(0) >::type * = nullptr> + template::value >::type * = nullptr> void maybe_has_equal_operator() {} - template(0) >::type * = nullptr> + template::value >::type * = nullptr> void maybe_has_not_equal_operator() { cl.def(pybind11::self != pybind11::self); } - template(0) >::type * = nullptr> + template::value >::type * = nullptr> void maybe_has_not_equal_operator() {} - #ifdef INSERTION_OPERATOR_IMPLEMENTATION - template() >::type * = nullptr> + template::value >::type * = nullptr> void maybe_has_insertion_operator(char const *name) { cl.def("__repr__", [name](typename vector_binder::Vector &v) { std::ostringstream s; s << name << '['; - for(uint i=0; i() >::type * = nullptr> + template::value >::type * = nullptr> void maybe_has_insertion_operator(char const *) {} - #endif - public: @@ -242,9 +252,7 @@ public: maybe_has_not_equal_operator(); // Printing - #ifdef INSERTION_OPERATOR_IMPLEMENTATION maybe_has_insertion_operator(name); - #endif // C++ style functions deprecated, leaving it here as an example //cl.def("empty", &Vector::empty, "checks whether the container is empty");