Const correctness fix for result_of::deref_data

This commit is contained in:
Joel de Guzman
2014-11-19 07:54:28 +08:00
parent c65000eac8
commit c952a5c053
2 changed files with 22 additions and 3 deletions

View File

@ -12,7 +12,10 @@
#include <boost/fusion/iterator/iterator_facade.hpp> #include <boost/fusion/iterator/iterator_facade.hpp>
#include <boost/mpl/minus.hpp> #include <boost/mpl/minus.hpp>
#include <boost/mpl/equal_to.hpp> #include <boost/mpl/equal_to.hpp>
#include <boost/mpl/if.hpp>
#include <boost/utility/declval.hpp> #include <boost/utility/declval.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/type_traits/add_const.hpp>
namespace boost { namespace fusion namespace boost { namespace fusion
{ {
@ -83,11 +86,18 @@ namespace boost { namespace fusion
{ {
typedef typename Iterator::sequence sequence; typedef typename Iterator::sequence sequence;
typedef typename Iterator::index index; typedef typename Iterator::index index;
typedef decltype(boost::declval<sequence>().get(index()).second) second_type_;
typedef typename typedef typename
add_reference< mpl::if_<
decltype(boost::declval<sequence>().get(index()).second) is_const<sequence>
, typename add_const<second_type_>::type
, second_type_
>::type >::type
type; second_type;
typedef typename add_reference<second_type>::type type;
BOOST_FUSION_GPU_ENABLED BOOST_FUSION_GPU_ENABLED
static type static type

View File

@ -149,6 +149,15 @@ main()
BOOST_STATIC_ASSERT((boost::is_same<r_type, int&>::value)); BOOST_STATIC_ASSERT((boost::is_same<r_type, int&>::value));
} }
{
// compile test only
// make sure result_of::deref_data is const correct
typedef map<pair<float, int> > const map_type;
typedef boost::fusion::result_of::begin<map_type>::type i_type;
typedef boost::fusion::result_of::deref_data<i_type>::type r_type;
BOOST_STATIC_ASSERT((boost::is_same<r_type, int const&>::value));
}
return boost::report_errors(); return boost::report_errors();
} }