From e962c1abb5312df23868a83ac66dd9da9773ca5f Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Wed, 18 Apr 2018 22:31:35 +0900 Subject: [PATCH 1/5] Fixed vector compile error with C-style array --- .../boost/fusion/container/vector/detail/value_at_impl.hpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/boost/fusion/container/vector/detail/value_at_impl.hpp b/include/boost/fusion/container/vector/detail/value_at_impl.hpp index a2b9b2f6..d7270aed 100644 --- a/include/boost/fusion/container/vector/detail/value_at_impl.hpp +++ b/include/boost/fusion/container/vector/detail/value_at_impl.hpp @@ -23,6 +23,7 @@ /////////////////////////////////////////////////////////////////////////////// #include #include +#include namespace boost { namespace fusion { @@ -35,7 +36,7 @@ namespace boost { namespace fusion template static inline BOOST_FUSION_GPU_ENABLED - U value_at_impl(store const volatile*); + mpl::identity value_at_impl(store const volatile*); } namespace extension @@ -49,8 +50,8 @@ namespace boost { namespace fusion template struct apply { - typedef - decltype(vector_detail::value_at_impl(boost::declval())) + typedef typename + decltype(vector_detail::value_at_impl(boost::declval()))::type type; }; }; From 96b2e51828e2df9bf6540a62687b9e62bf4039c8 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Wed, 18 Apr 2018 22:33:36 +0900 Subject: [PATCH 2/5] Added test for #176 --- test/Jamfile | 1 + test/sequence/github-176.cpp | 50 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 test/sequence/github-176.cpp diff --git a/test/Jamfile b/test/Jamfile index a61239d0..9492e83f 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -237,6 +237,7 @@ project [ run sequence/ref_vector.cpp ] [ run sequence/flatten_view.cpp ] [ compile sequence/github-159.cpp ] + [ run sequence/github-176.cpp ] [ compile sequence/size.cpp ] diff --git a/test/sequence/github-176.cpp b/test/sequence/github-176.cpp new file mode 100644 index 00000000..553e83c2 --- /dev/null +++ b/test/sequence/github-176.cpp @@ -0,0 +1,50 @@ +/*============================================================================= + Copyright (c) 2018 Kohei Takahashi + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +==============================================================================*/ + +#include +#include +#include +#include +#include +#include + +template +void test_at() +{ + Sequence seq; + + // zero initialized + BOOST_TEST(boost::fusion::at_c<0>(seq)[0] == 0); + BOOST_TEST(boost::fusion::at_c<0>(seq)[1] == 0); + BOOST_TEST(boost::fusion::at_c<0>(seq)[2] == 0); + + int (&arr)[3] = boost::fusion::deref(boost::fusion::begin(seq)); + + arr[0] = 2; + arr[1] = 4; + arr[2] = 6; + + BOOST_TEST(boost::fusion::at_c<0>(seq)[0] == 2); + BOOST_TEST(boost::fusion::at_c<0>(seq)[1] == 4); + BOOST_TEST(boost::fusion::at_c<0>(seq)[2] == 6); + + boost::fusion::at_c<0>(seq)[1] = 42; + + BOOST_TEST(boost::fusion::at_c<0>(seq)[0] == 2); + BOOST_TEST(boost::fusion::at_c<0>(seq)[1] == 42); + BOOST_TEST(boost::fusion::at_c<0>(seq)[2] == 6); +} + +int main() +{ + using namespace boost::fusion; + + test_at >(); + test_at >(); + test_at >(); + test_at >(); +} From dd695c1dbd07476d324fbd7973008fbafc129748 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Wed, 18 Apr 2018 22:38:09 +0900 Subject: [PATCH 3/5] Fixed a compile error bug similar to previous vector's one --- include/boost/fusion/container/map/detail/map_impl.hpp | 6 +----- .../fusion/container/map/detail/value_at_key_impl.hpp | 7 ++----- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/include/boost/fusion/container/map/detail/map_impl.hpp b/include/boost/fusion/container/map/detail/map_impl.hpp index c62145ba..360c5d09 100644 --- a/include/boost/fusion/container/map/detail/map_impl.hpp +++ b/include/boost/fusion/container/map/detail/map_impl.hpp @@ -125,11 +125,7 @@ namespace boost { namespace fusion { namespace detail } BOOST_FUSION_GPU_ENABLED - value_type get_val(mpl::identity); - BOOST_FUSION_GPU_ENABLED - pair_type get_val(mpl::int_); - BOOST_FUSION_GPU_ENABLED - value_type get_val(mpl::identity) const; + mpl::identity get_val(mpl::identity) const; BOOST_FUSION_GPU_ENABLED pair_type get_val(mpl::int_) const; diff --git a/include/boost/fusion/container/map/detail/value_at_key_impl.hpp b/include/boost/fusion/container/map/detail/value_at_key_impl.hpp index 94d2da47..10873087 100644 --- a/include/boost/fusion/container/map/detail/value_at_key_impl.hpp +++ b/include/boost/fusion/container/map/detail/value_at_key_impl.hpp @@ -8,9 +8,6 @@ #define BOOST_FUSION_MAP_DETAIL_VALUE_AT_KEY_IMPL_02042013_0821 #include -#include -#include -#include #include #include @@ -29,8 +26,8 @@ namespace boost { namespace fusion template struct apply { - typedef - decltype(boost::declval().get_val(mpl::identity())) + typedef typename + decltype(boost::declval().get_val(mpl::identity()))::type type; }; }; From 757541f9d2f22faebf18665c3b6fe03203b428cf Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Wed, 18 Apr 2018 22:39:55 +0900 Subject: [PATCH 4/5] Updated c-style array test for associative container --- test/sequence/github-176.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/sequence/github-176.cpp b/test/sequence/github-176.cpp index 553e83c2..82960e9a 100644 --- a/test/sequence/github-176.cpp +++ b/test/sequence/github-176.cpp @@ -6,9 +6,12 @@ ==============================================================================*/ #include +#include #include #include #include +#include +#include #include #include @@ -39,6 +42,36 @@ void test_at() BOOST_TEST(boost::fusion::at_c<0>(seq)[2] == 6); } +template inline T& value(T& v) { return v; } +template inline T& value(boost::fusion::pair& v) { return v.second; } + +template +void test_at_key() +{ + Sequence seq; + + // zero initialized + BOOST_TEST(boost::fusion::at_key(seq)[0] == 0); + BOOST_TEST(boost::fusion::at_key(seq)[1] == 0); + BOOST_TEST(boost::fusion::at_key(seq)[2] == 0); + + int (&arr)[3] = value(boost::fusion::deref(boost::fusion::begin(seq))); + + arr[0] = 2; + arr[1] = 4; + arr[2] = 6; + + BOOST_TEST(boost::fusion::at_key(seq)[0] == 2); + BOOST_TEST(boost::fusion::at_key(seq)[1] == 4); + BOOST_TEST(boost::fusion::at_key(seq)[2] == 6); + + boost::fusion::at_key(seq)[1] = 42; + + BOOST_TEST(boost::fusion::at_key(seq)[0] == 2); + BOOST_TEST(boost::fusion::at_key(seq)[1] == 42); + BOOST_TEST(boost::fusion::at_key(seq)[2] == 6); +} + int main() { using namespace boost::fusion; @@ -47,4 +80,7 @@ int main() test_at >(); test_at >(); test_at >(); + + test_at_key >(); + test_at_key > >(); } From a273cd8131a5b5ebd25282e8c79f68e25a5f2610 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Thu, 19 Apr 2018 00:21:41 +0900 Subject: [PATCH 5/5] Added workaround for msvc-14.x --- .../container/map/detail/value_at_key_impl.hpp | 8 ++++---- .../container/vector/detail/value_at_impl.hpp | 9 ++++----- include/boost/fusion/support/config.hpp | 14 +++++++++++++- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/include/boost/fusion/container/map/detail/value_at_key_impl.hpp b/include/boost/fusion/container/map/detail/value_at_key_impl.hpp index 10873087..da6259e6 100644 --- a/include/boost/fusion/container/map/detail/value_at_key_impl.hpp +++ b/include/boost/fusion/container/map/detail/value_at_key_impl.hpp @@ -1,5 +1,6 @@ /*============================================================================= Copyright (c) 2001-2013 Joel de Guzman + Copyright (c) 2018 Kohei Takahashi Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -8,7 +9,6 @@ #define BOOST_FUSION_MAP_DETAIL_VALUE_AT_KEY_IMPL_02042013_0821 #include -#include #include namespace boost { namespace fusion @@ -26,9 +26,9 @@ namespace boost { namespace fusion template struct apply { - typedef typename - decltype(boost::declval().get_val(mpl::identity()))::type - type; + typedef typename BOOST_FUSION_IDENTIFIED_TYPE(( + boost::declval().get_val(mpl::identity()) + )) type; }; }; } diff --git a/include/boost/fusion/container/vector/detail/value_at_impl.hpp b/include/boost/fusion/container/vector/detail/value_at_impl.hpp index d7270aed..a2dd5fcd 100644 --- a/include/boost/fusion/container/vector/detail/value_at_impl.hpp +++ b/include/boost/fusion/container/vector/detail/value_at_impl.hpp @@ -1,5 +1,5 @@ /*============================================================================= - Copyright (c) 2014 Kohei Takahashi + Copyright (c) 2014,2018 Kohei Takahashi Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -7,7 +7,6 @@ #ifndef FUSION_VALUE_AT_IMPL_16122014_1641 #define FUSION_VALUE_AT_IMPL_16122014_1641 -#include #include #include @@ -50,9 +49,9 @@ namespace boost { namespace fusion template struct apply { - typedef typename - decltype(vector_detail::value_at_impl(boost::declval()))::type - type; + typedef typename BOOST_FUSION_IDENTIFIED_TYPE(( + vector_detail::value_at_impl(boost::declval()) + )) type; }; }; } diff --git a/include/boost/fusion/support/config.hpp b/include/boost/fusion/support/config.hpp index 23554531..65fe2f35 100644 --- a/include/boost/fusion/support/config.hpp +++ b/include/boost/fusion/support/config.hpp @@ -1,6 +1,6 @@ /*============================================================================= Copyright (c) 2014 Eric Niebler - Copyright (c) 2014 Kohei Takahashi + Copyright (c) 2014,2018 Kohei Takahashi Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -96,4 +96,16 @@ namespace std #define BOOST_FUSION_CONSTEXPR_THIS BOOST_CONSTEXPR #endif + +// Workaround for compiler which doesn't compile decltype(expr)::type. +// It expects decltype(expr) deduced as mpl::identity. +#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1913)) +# include +# define BOOST_FUSION_IDENTIFIED_TYPE(parenthesized_expr) \ + boost::mpl::identity::type::type +#else +# define BOOST_FUSION_IDENTIFIED_TYPE(parenthesized_expr) \ + decltype parenthesized_expr ::type +#endif + #endif