Boost logo

Boost Users :

Subject: [Boost-users] Heap: what is expected from T?
From: Akim Demaille (akim_at_[hidden])
Date: 2015-09-28 09:09:04


Hi,

I'm using a heap whose elements are value_type from a map; hence the key type is const. Some heaps seem to accept this gracefully, other just fail to compile. Is this expected? I saw no requirement about T in the documentation. This is Boost 1.59 from Mac Ports, on OS X.

$ cat foo.cc
#include <tuple>
#include <string>
#include <boost/heap/priority_queue.hpp>
#include <boost/heap/fibonacci_heap.hpp>

int main()
{
  using datum_t = std::tuple<const std::string>;
  {
    using queue_t = boost::heap::fibonacci_heap<datum_t>;
    auto q = queue_t{};
    q.emplace("foo");
  }
  {
    using queue_t = boost::heap::priority_queue<datum_t>;
    auto q = queue_t{};
    q.emplace("foo");
  }
}
$ clang++-mp-3.7 -std=c++11 /tmp/foo.cc -isystem /opt/local/include
In file included from /tmp/foo.cc:1:
/opt/local/libexec/llvm-3.7/bin/../include/c++/v1/tuple:283:19: error: no viable overloaded '='
            value = _VSTD::forward<_Tp>(__t);
            ~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~
/opt/local/libexec/llvm-3.7/bin/../include/c++/v1/tuple:485:45: note: in instantiation of function template specialization 'std::__1::__tuple_leaf<0, const
      std::__1::basic_string<char>, false>::operator=<const std::__1::basic_string<char> >' requested here
        __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...);
                                            ^
/opt/local/libexec/llvm-3.7/bin/../include/c++/v1/tuple:498:29: note: in instantiation of member function 'std::__1::__tuple_impl<std::__1::__tuple_indices<0>, const
      std::__1::basic_string<char> >::operator=' requested here
class _LIBCPP_TYPE_VIS_ONLY tuple
                            ^
/opt/local/libexec/llvm-3.7/bin/../include/c++/v1/algorithm:4848:5: note: in instantiation of function template specialization
      'std::__1::__sift_up<boost::heap::detail::heap_base<std::__1::tuple<const std::__1::basic_string<char> >, std::__1::less<std::__1::tuple<const std::__1::basic_string<char> >
>, false, unsigned long, false> &, std::__1::__wrap_iter<std::__1::tuple<const std::__1::basic_string<char> > *> >' requested here
    __sift_up<_Comp_ref>(__first, __last, __comp, __last - __first);
    ^
/opt/local/include/boost/heap/priority_queue.hpp:261:14: note: in instantiation of function template specialization 'std::__1::push_heap<std::__1::__wrap_iter<std::__1::tuple<const
      std::__1::basic_string<char> > *>, boost::heap::detail::heap_base<std::__1::tuple<const std::__1::basic_string<char> >, std::__1::less<std::__1::tuple<const
      std::__1::basic_string<char> > >, false, unsigned long, false> >' requested here
        std::push_heap(q_.begin(), q_.end(), static_cast<super_t const &>(*this));
             ^
/tmp/foo.cc:17:7: note: in instantiation of function template specialization 'boost::heap::priority_queue<std::__1::tuple<const std::__1::basic_string<char> >,
      boost::parameter::void_, boost::parameter::void_, boost::parameter::void_, boost::parameter::void_>::emplace<char const (&)[4]>' requested here
    q.emplace("foo");
      ^
/opt/local/libexec/llvm-3.7/bin/../include/c++/v1/string:1376:19: note: candidate function not viable: 'this' argument has type 'const std::__1::basic_string<char>', but method is
      not marked const
    basic_string& operator=(const basic_string& __str);
                  ^
/opt/local/libexec/llvm-3.7/bin/../include/c++/v1/string:1379:19: note: candidate function not viable: 'this' argument has type 'const std::__1::basic_string<char>', but method is
      not marked const
    basic_string& operator=(basic_string&& __str)
                  ^
/opt/local/libexec/llvm-3.7/bin/../include/c++/v1/string:1383:45: note: candidate function not viable: 'this' argument has type 'const std::__1::basic_string<char>', but method is
      not marked const
    _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
                                            ^
/opt/local/libexec/llvm-3.7/bin/../include/c++/v1/string:1384:19: note: candidate function not viable: 'this' argument has type 'const std::__1::basic_string<char>', but method is
      not marked const
    basic_string& operator=(value_type __c);
                  ^
/opt/local/libexec/llvm-3.7/bin/../include/c++/v1/string:1387:19: note: candidate function not viable: 'this' argument has type 'const std::__1::basic_string<char>', but method is
      not marked const
    basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
                  ^
1 error generated.

Thanks in advance.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net