[Boost-bugs] [Boost C++ Libraries] #12423: fusion::make_map breaks when passing references

Subject: [Boost-bugs] [Boost C++ Libraries] #12423: fusion::make_map breaks when passing references
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-08-30 15:51:30


#12423: fusion::make_map breaks when passing references
------------------------------+---------------------
 Reporter: oleg00@… | Owner: djowel
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: fusion
  Version: Boost 1.61.0 | Severity: Problem
 Keywords: fusion make_map |
------------------------------+---------------------
 When using variadic maps the following code doesn't compile:

 {{{
 int i = 0;
 fusion::make_map<int>(ref(i));
 }}}


 Clang gives this error:
 error : no matching constructor for initialization of 'detail::map_impl<0,
 pair<int, int &> >'
 1> : base_type(first, rest...)
 1> ^ ~~~~~

 There is a constructor in fusion::pair that can do the required
 conversion:

 {{{
        template <typename Second2>
         BOOST_FUSION_GPU_ENABLED
         pair(Second2&& val
           , typename boost::disable_if<is_lvalue_reference<Second2>
>::type* /* dummy */ = 0
           , typename boost::enable_if<is_convertible<Second2, Second>
>::type* /*dummy*/ = 0
         ) : second(BOOST_FUSION_FWD_ELEM(Second, val)) {}

 }}}


 But it's not being invoked since there's no make_map function that takes
 rvalue refs. I was able to make this work by adding another make_map
 overload:


 {{{
    template <typename ...Key, typename ...T>
     BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
       inline map<
       fusion::pair<
       Key
       , typename detail::as_fusion_element<T>::type
>...>
       make_map(T &&... arg)
     {
       typedef map<
         fusion::pair<
         Key
         , typename detail::as_fusion_element<T>::type
>...>
         result_type;

       return result_type(std::forward<T>(arg)...);
     }

 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12423>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC