Merge pull request #177 from boostorg/bugfix/c-style-array

Fixed compile error with C-style array
This commit is contained in:
Kohei Takahashi
2018-04-19 01:44:13 +09:00
committed by GitHub
6 changed files with 111 additions and 19 deletions

View File

@@ -125,11 +125,7 @@ namespace boost { namespace fusion { namespace detail
} }
BOOST_FUSION_GPU_ENABLED BOOST_FUSION_GPU_ENABLED
value_type get_val(mpl::identity<key_type>); mpl::identity<value_type> get_val(mpl::identity<key_type>) const;
BOOST_FUSION_GPU_ENABLED
pair_type get_val(mpl::int_<index>);
BOOST_FUSION_GPU_ENABLED
value_type get_val(mpl::identity<key_type>) const;
BOOST_FUSION_GPU_ENABLED BOOST_FUSION_GPU_ENABLED
pair_type get_val(mpl::int_<index>) const; pair_type get_val(mpl::int_<index>) const;

View File

@@ -1,5 +1,6 @@
/*============================================================================= /*=============================================================================
Copyright (c) 2001-2013 Joel de Guzman Copyright (c) 2001-2013 Joel de Guzman
Copyright (c) 2018 Kohei Takahashi
Distributed under the Boost Software License, Version 1.0. (See accompanying 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) file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -8,10 +9,6 @@
#define BOOST_FUSION_MAP_DETAIL_VALUE_AT_KEY_IMPL_02042013_0821 #define BOOST_FUSION_MAP_DETAIL_VALUE_AT_KEY_IMPL_02042013_0821
#include <boost/fusion/support/config.hpp> #include <boost/fusion/support/config.hpp>
#include <boost/fusion/support/detail/access.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/mpl/at.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/utility/declval.hpp> #include <boost/utility/declval.hpp>
namespace boost { namespace fusion namespace boost { namespace fusion
@@ -29,9 +26,9 @@ namespace boost { namespace fusion
template <typename Sequence, typename Key> template <typename Sequence, typename Key>
struct apply struct apply
{ {
typedef typedef typename BOOST_FUSION_IDENTIFIED_TYPE((
decltype(boost::declval<Sequence>().get_val(mpl::identity<Key>())) boost::declval<Sequence>().get_val(mpl::identity<Key>())
type; )) type;
}; };
}; };
} }

View File

@@ -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 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) 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 #ifndef FUSION_VALUE_AT_IMPL_16122014_1641
#define FUSION_VALUE_AT_IMPL_16122014_1641 #define FUSION_VALUE_AT_IMPL_16122014_1641
#include <boost/config.hpp>
#include <boost/fusion/support/config.hpp> #include <boost/fusion/support/config.hpp>
#include <boost/fusion/container/vector/detail/config.hpp> #include <boost/fusion/container/vector/detail/config.hpp>
@@ -23,6 +22,7 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#include <boost/fusion/container/vector/vector_fwd.hpp> #include <boost/fusion/container/vector/vector_fwd.hpp>
#include <boost/type_traits/declval.hpp> #include <boost/type_traits/declval.hpp>
#include <boost/mpl/identity.hpp>
namespace boost { namespace fusion namespace boost { namespace fusion
{ {
@@ -35,7 +35,7 @@ namespace boost { namespace fusion
template <std::size_t N, typename U> template <std::size_t N, typename U>
static inline BOOST_FUSION_GPU_ENABLED static inline BOOST_FUSION_GPU_ENABLED
U value_at_impl(store<N, U> const volatile*); mpl::identity<U> value_at_impl(store<N, U> const volatile*);
} }
namespace extension namespace extension
@@ -49,9 +49,9 @@ namespace boost { namespace fusion
template <typename Sequence, typename N> template <typename Sequence, typename N>
struct apply struct apply
{ {
typedef typedef typename BOOST_FUSION_IDENTIFIED_TYPE((
decltype(vector_detail::value_at_impl<N::value>(boost::declval<Sequence*>())) vector_detail::value_at_impl<N::value>(boost::declval<Sequence*>())
type; )) type;
}; };
}; };
} }

View File

@@ -1,6 +1,6 @@
/*============================================================================= /*=============================================================================
Copyright (c) 2014 Eric Niebler 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 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) 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 #define BOOST_FUSION_CONSTEXPR_THIS BOOST_CONSTEXPR
#endif #endif
// Workaround for compiler which doesn't compile decltype(expr)::type.
// It expects decltype(expr) deduced as mpl::identity<T>.
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1913))
# include <boost/mpl/identity.hpp>
# define BOOST_FUSION_IDENTIFIED_TYPE(parenthesized_expr) \
boost::mpl::identity<decltype parenthesized_expr>::type::type
#else
# define BOOST_FUSION_IDENTIFIED_TYPE(parenthesized_expr) \
decltype parenthesized_expr ::type
#endif
#endif #endif

View File

@@ -237,6 +237,7 @@ project
[ run sequence/ref_vector.cpp ] [ run sequence/ref_vector.cpp ]
[ run sequence/flatten_view.cpp ] [ run sequence/flatten_view.cpp ]
[ compile sequence/github-159.cpp ] [ compile sequence/github-159.cpp ]
[ run sequence/github-176.cpp ]
[ compile sequence/size.cpp ] [ compile sequence/size.cpp ]

View File

@@ -0,0 +1,86 @@
/*=============================================================================
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 <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/fusion/sequence/intrinsic/at_key.hpp>
#include <boost/fusion/container/vector.hpp>
#include <boost/fusion/container/list.hpp>
#include <boost/fusion/container/deque.hpp>
#include <boost/fusion/container/map.hpp>
#include <boost/fusion/container/set.hpp>
#include <boost/fusion/tuple/tuple.hpp>
#include <boost/core/lightweight_test.hpp>
template <typename Sequence>
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);
}
template <typename T> inline T& value(T& v) { return v; }
template <typename K, typename T> inline T& value(boost::fusion::pair<K, T>& v) { return v.second; }
template <typename Sequence>
void test_at_key()
{
Sequence seq;
// zero initialized
BOOST_TEST(boost::fusion::at_key<int[3]>(seq)[0] == 0);
BOOST_TEST(boost::fusion::at_key<int[3]>(seq)[1] == 0);
BOOST_TEST(boost::fusion::at_key<int[3]>(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<int[3]>(seq)[0] == 2);
BOOST_TEST(boost::fusion::at_key<int[3]>(seq)[1] == 4);
BOOST_TEST(boost::fusion::at_key<int[3]>(seq)[2] == 6);
boost::fusion::at_key<int[3]>(seq)[1] = 42;
BOOST_TEST(boost::fusion::at_key<int[3]>(seq)[0] == 2);
BOOST_TEST(boost::fusion::at_key<int[3]>(seq)[1] == 42);
BOOST_TEST(boost::fusion::at_key<int[3]>(seq)[2] == 6);
}
int main()
{
using namespace boost::fusion;
test_at<vector<int[3]> >();
test_at<deque<int[3]> >();
test_at<list<int[3]> >();
test_at<tuple<int[3]> >();
test_at_key<set<int[3]> >();
test_at_key<map<pair<int[3], int[3]> > >();
}