Opened 8 years ago

Closed 8 years ago

#10003 closed Bugs (fixed)

Fibonacci heaps base class not copy constructible.

Reported by: Raffi Enficiaud Owned by: timblechmann
Milestone: To Be Determined Component: heap
Version: Boost 1.55.0 Severity: Problem
Keywords: Cc: raffi.enficiaud@…

Description

The following code does not compile on Windows / Visual Express 2013 x64.

Code highlighting:

BOOST_AUTO_TEST_CASE(test_heap_vector)
{
  typedef boost::heap::fibonacci_heap<double, boost::heap::compare< std::less<double> > > low_heap_t;
  
  low_heap_t lowh;
  
  const int K = 7;
  
  boost::random::uniform_real_distribution<double> dist;
  // preparing the heap
  for(int i = 0; i < 100; i++)
  {
    double current = dist(rng);
    if(lowh.size() < K)
    {
      lowh.push(current);
    }
    else if(lowh.value_comp()(current, lowh.top()))
    {
      lowh.push(current);
      lowh.pop();
    }
  }
  
  BOOST_CHECK_EQUAL(lowh.size(), K);

  // duplicating in the vector
  std::vector<low_heap_t> v(10, lowh);
  for(int i = 0; i < 10; i++)
  {
    BOOST_CHECK_EQUAL(v[i].size(), K);
  }
}

The compiler gives me this:

1>d:\Code\thirdparties\visual2013x64\boost_1_55\include\boost-1_55\boost/heap/fibonacci_heap.hpp(224): error C2664: 'boost::heap::detail::make_fibonacci_heap_base<T,boost::parameter::aux::arg_list<boost::heap::compare<std::less<double>>,ArgumentPack>>::type::type(boost::heap::detail::make_fibonacci_heap_base<T,boost::parameter::aux::arg_list<boost::heap::compare<std::less<double>>,ArgumentPack>>::type &)' : impossible de convertir l'argument 1 de 'const boost::heap::fibonacci_heap<double,boost::heap::compare<std::less<double>>,boost::parameter::void_,boost::parameter::void_,boost::parameter::void_,boost::parameter::void_>' en 'const std::less<double> &'
1>          with
1>          [
1>              T=double
1>  ,            ArgumentPack=boost::parameter::aux::empty_arg_list
1>          ]
1>          Raison : impossible de convertir de 'const boost::heap::fibonacci_heap<double,boost::heap::compare<std::less<double>>,boost::parameter::void_,boost::parameter::void_,boost::parameter::void_,boost::parameter::void_>' en 'const std::less<double>'
1>          Aucun opérateur de conversion définie par l'utilisateur disponible qui puisse effectuer cette conversion, ou l'opérateur ne peut pas être appelé
1>          d:\Code\thirdparties\visual2013x64\boost_1_55\include\boost-1_55\boost/heap/fibonacci_heap.hpp(222) : lors de la compilation de la fonction membre 'boost::heap::fibonacci_heap<double,boost::heap::compare<std::less<double>>,boost::parameter::void_,boost::parameter::void_,boost::parameter::void_,boost::parameter::void_>::fibonacci_heap(const boost::heap::fibonacci_heap<double,boost::heap::compare<std::less<double>>,boost::parameter::void_,boost::parameter::void_,boost::parameter::void_,boost::parameter::void_> &)' de la classe modèle
1>          C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(593) : voir la référence à l'instanciation de la fonction modèle 'boost::heap::fibonacci_heap<double,boost::heap::compare<std::less<double>>,boost::parameter::void_,boost::parameter::void_,boost::parameter::void_,boost::parameter::void_>::fibonacci_heap(const boost::heap::fibonacci_heap<double,boost::heap::compare<std::less<double>>,boost::parameter::void_,boost::parameter::void_,boost::parameter::void_,boost::parameter::void_> &)' en cours de compilation
========== Génération : 0 a réussi, 1 a échoué, 0 mis à jour, 0 a été ignoré ==========

Apparently it comes from

Code highlighting:

  make_fibonacci_heap_base::type

Creating a copy constructor and moving the assignment operator out of the #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES / #endif seems to work.

Code highlighting:

    struct type:
        base_type,
        allocator_type
    {
        type(compare_argument const & arg):
            base_type(arg)
        {}
        type(type const & rhs):
            base_type(static_cast<base_type const &>(rhs)),
            allocator_type(static_cast<allocator_type const&>(rhs))
        {}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
        type(type && rhs):
            base_type(std::move(static_cast<base_type&>(rhs))),
            allocator_type(std::move(static_cast<allocator_type&>(rhs)))
        {}

        type(type & rhs):
            base_type(static_cast<base_type&>(rhs)),
            allocator_type(static_cast<allocator_type&>(rhs))
        {}

        type & operator=(type && rhs)
        {
            base_type::operator=(std::move(static_cast<base_type&>(rhs)));
            allocator_type::operator=(std::move(static_cast<allocator_type&>(rhs)));
            return *this;
        }
#endif
        type & operator=(type const & rhs)
        {
            base_type::operator=(static_cast<base_type const &>(rhs));
            allocator_type::operator=(static_cast<allocator_type const &>(rhs));
            return *this;
        }

    };

Change History (2)

comment:1 by Raffi Enficiaud, 8 years ago

Cc: raffi.enficiaud@… added

comment:2 by timblechmann, 8 years ago

Resolution: fixed
Status: newclosed

fixed in develop!

Note: See TracTickets for help on using tickets.