Fixed C++11 implementation of map's result_of::deref_data to return a

reference as expected.
This commit is contained in:
Joel de Guzman
2014-11-18 23:11:13 +08:00
parent 68b4683e95
commit 0f34b3a692
3 changed files with 18 additions and 8 deletions

View File

@ -513,7 +513,7 @@ Deferences the data property associated with the element referenced by an associ
#include <boost/fusion/include/deref_data.hpp> #include <boost/fusion/include/deref_data.hpp>
[heading Example] [heading Example]
typedef __map__<__pair__<float,int&> > map; typedef __map__<__pair__<float, int&> > map;
int i(0); int i(0);
map m(1.0f,i); map m(1.0f,i);
@ -1070,14 +1070,13 @@ Returns the type that will be returned by dereferencing the data property refere
#include <boost/fusion/include/deref_data.hpp> #include <boost/fusion/include/deref_data.hpp>
[heading Example] [heading Example]
typedef __map__<__pair__<float,int> > map; typedef map<pair<float, int> > map_type;
typedef __result_of_begin__<vec>::type first; typedef boost::fusion::result_of::begin<map_type>::type i_type;
typedef boost::fusion::result_of::deref_data<i_type>::type r_type;
BOOST_MPL_ASSERT((boost::is_same<__result_of_deref_data__<first>::type, int&>)); BOOST_STATIC_ASSERT((boost::is_same<r_type, int&>::value));
[endsect] [endsect]
[endsect] [endsect]
[endsect] [endsect]

View File

@ -83,8 +83,10 @@ 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 typedef typename
decltype(boost::declval<sequence>().get(index()).second) add_reference<
decltype(boost::declval<sequence>().get(index()).second)
>::type
type; type;
BOOST_FUSION_GPU_ENABLED BOOST_FUSION_GPU_ENABLED

View File

@ -139,6 +139,15 @@ main()
pair<int, copy_all> p1; pair<int, copy_all> p1;
pair<int, copy_all> p2 = p1; pair<int, copy_all> p2 = p1;
} }
{
// compile test only
// make sure result_of::deref_data returns a reference
typedef map<pair<float, int> > 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&>::value));
}
return boost::report_errors(); return boost::report_errors();
} }