From 0f34b3a692924148440f40bcdb4d412611d503ef Mon Sep 17 00:00:00 2001 From: Joel de Guzman Date: Tue, 18 Nov 2014 23:11:13 +0800 Subject: [PATCH] Fixed C++11 implementation of map's result_of::deref_data to return a reference as expected. --- doc/iterator.qbk | 11 +++++------ include/boost/fusion/container/map/map_iterator.hpp | 6 ++++-- test/sequence/map.cpp | 9 +++++++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/doc/iterator.qbk b/doc/iterator.qbk index c4f2c741..50430a4d 100644 --- a/doc/iterator.qbk +++ b/doc/iterator.qbk @@ -513,7 +513,7 @@ Deferences the data property associated with the element referenced by an associ #include [heading Example] - typedef __map__<__pair__ > map; + typedef __map__<__pair__ > map; int i(0); map m(1.0f,i); @@ -1070,14 +1070,13 @@ Returns the type that will be returned by dereferencing the data property refere #include [heading Example] - typedef __map__<__pair__ > map; - typedef __result_of_begin__::type first; - - BOOST_MPL_ASSERT((boost::is_same<__result_of_deref_data__::type, int&>)); + typedef map > map_type; + typedef boost::fusion::result_of::begin::type i_type; + typedef boost::fusion::result_of::deref_data::type r_type; + BOOST_STATIC_ASSERT((boost::is_same::value)); [endsect] [endsect] [endsect] - diff --git a/include/boost/fusion/container/map/map_iterator.hpp b/include/boost/fusion/container/map/map_iterator.hpp index db89738e..03242026 100644 --- a/include/boost/fusion/container/map/map_iterator.hpp +++ b/include/boost/fusion/container/map/map_iterator.hpp @@ -83,8 +83,10 @@ namespace boost { namespace fusion { typedef typename Iterator::sequence sequence; typedef typename Iterator::index index; - typedef - decltype(boost::declval().get(index()).second) + typedef typename + add_reference< + decltype(boost::declval().get(index()).second) + >::type type; BOOST_FUSION_GPU_ENABLED diff --git a/test/sequence/map.cpp b/test/sequence/map.cpp index 925d6720..9e4ecafb 100644 --- a/test/sequence/map.cpp +++ b/test/sequence/map.cpp @@ -139,6 +139,15 @@ main() pair p1; pair p2 = p1; } + + { + // compile test only + // make sure result_of::deref_data returns a reference + typedef map > map_type; + typedef boost::fusion::result_of::begin::type i_type; + typedef boost::fusion::result_of::deref_data::type r_type; + BOOST_STATIC_ASSERT((boost::is_same::value)); + } return boost::report_errors(); }