Inserting a boost::unique_ptr in std::map - c++

I'm trying to store a boost::unique_ptr in a std::map. The compiler I'm using is g++ 3.4 (/usr/bin/g++34 -I./boost_1_62_0/ test_boost_unique_ptr.cpp).
#include <iostream>
#include <map>
#include <boost/move/unique_ptr.hpp>
#include <boost/move/make_unique.hpp>
#include <boost/ptr_container/ptr_map.hpp>
using namespace boost::movelib;
typedef std::map<const int, unique_ptr<int> > MGR_T;
typedef MGR_T::const_iterator MGR_ITER_T;
MGR_T mgrPluginCache;
int main()
{
unique_ptr<int> p (new int(10));
std::cout << "p = " << *p << std::endl;
mgrPluginCache.insert(std::make_pair(1, boost::move(p)));
// mgrPluginCache[0] = (boost::move(p));
return 0;
}
This results in compilation error:
In function `int main()':
./boost_1_62_0/boost/move/core.hpp:94: error: `boost::rv<T>::rv(const boost::rv<T>&) [with T = boost::movelib::unique_ptr<int, boost::movelib::default_delete<int> >]' is private
test_boost_unique_ptr.cpp:37: error: within this context
test_boost_unique_ptr.cpp:37: error: initializing argument 2 of `std::pair<_T1, _T2> std::make_pair(_T1, _T2) [with _T1 = int, _T2 = boost::rv<boost::movelib::unique_ptr<int, boost::movelib::default_delete<int> > >]'
./boost_1_62_0/boost/move/core.hpp:93: error: `boost::rv<T>::~rv() [with T = boost::movelib::unique_ptr<int, boost::movelib::default_delete<int> >]' is private
test_boost_unique_ptr.cpp:37: error: within this context
test_boost_unique_ptr.cpp: In destructor `std::pair<int, boost::rv<boost::movelib::unique_ptr<int, boost::movelib::default_delete<int> > > >::~pair()':
./boost_1_62_0/boost/move/core.hpp:93: error: `boost::rv<T>::~rv() [with T = boost::movelib::unique_ptr<int, boost::movelib::default_delete<int> >]' is private
test_boost_unique_ptr.cpp:37: error: within this context
test_boost_unique_ptr.cpp: In copy constructor `std::pair<int, boost::rv<boost::movelib::unique_ptr<int, boost::movelib::default_delete<int> > > >::pair(const std::pair<int, boost::rv<boost::movelib::unique_ptr<int, boost::movelib::default_delete<int> > > >&)':
./boost_1_62_0/boost/move/core.hpp:94: error: `boost::rv<T>::rv(const boost::rv<T>&) [with T = boost::movelib::unique_ptr<int, boost::movelib::default_delete<int> >]' is private
test_boost_unique_ptr.cpp:37: error: within this context
./boost_1_62_0/boost/move/core.hpp:93: error: `boost::rv<T>::~rv() [with T = boost::movelib::unique_ptr<int, boost::movelib::default_delete<int> >]' is private
test_boost_unique_ptr.cpp:37: error: within this context
./boost_1_62_0/boost/ptr_container/ptr_map_adapter.hpp: In member function `void boost::ptr_map_adapter<T, VoidPtrMap, CloneAllocator, Ordered>::insert(const Range&) [with Range = std::pair<int, boost::rv<boost::movelib::unique_ptr<int, boost::movelib::default_delete<int> > > >, T = boost::movelib::unique_ptr<int, boost::movelib::default_delete<int> >, VoidPtrMap = std::map<const int, void*, std::less<const int>, std::allocator<std::pair<const int, void*> > >, CloneAllocator = boost::heap_clone_allocator, bool Ordered = true]':
test_boost_unique_ptr.cpp:37: instantiated from here
./boost_1_62_0/boost/ptr_container/ptr_map_adapter.hpp:518: error: no matching function for call to `begin(const std::pair<int, boost::rv<boost::movelib::unique_ptr<int, boost::movelib::default_delete<int> > > >&)'
./boost_1_62_0/boost/ptr_container/ptr_map_adapter.hpp:518: error: no matching function for call to `end(const std::pair<int, boost::rv<boost::movelib::unique_ptr<int, boost::movelib::default_delete<int> > > >&)'
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_pair.h: In constructor `std::pair<_T1, _T2>::pair(const _T1&, const _T2&) [with _T1 = int, _T2 = boost::rv<boost::movelib::unique_ptr<int, boost::movelib::default_delete<int> > >]':
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_pair.h:144: instantiated from `std::pair<_T1, _T2> std::make_pair(_T1, _T2) [with _T1 = int, _T2 = boost::rv<boost::movelib::unique_ptr<int, boost::movelib::default_delete<int> > >]'
test_boost_unique_ptr.cpp:37: instantiated from here
./boost_1_62_0/boost/move/core.hpp:94: error: `boost::rv<T>::rv(const boost::rv<T>&) [with T = boost::movelib::unique_ptr<int, boost::movelib::default_delete<int> >]' is private
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_pair.h:85: error: within this context
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_pair.h:144: instantiated from `std::pair<_T1, _T2> std::make_pair(_T1, _T2) [with _T1 = int, _T2 = boost::rv<boost::movelib::unique_ptr<int, boost::movelib::default_delete<int> > >]'
test_boost_unique_ptr.cpp:37: instantiated from here
./boost_1_62_0/boost/move/core.hpp:93: error: `boost::rv<T>::~rv() [with T = boost::movelib::unique_ptr<int, boost::movelib::default_delete<int> >]' is private
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_pair.h:85: error: within this context
Is there a way to store the boost::unique_ptr in std::map? Is it allowed in earlier versions? Can we do this any other way? I cannot change the compiler, the code I'm working on is very old and has not been modified in long time.

value_type of std::map requires copy constructor for insert. boost::unique_ptr have a private copy constructor (which could have been deleted I suppose)
You can simply use emplace (you'll also need to std::move or boost::move it):
mgrPluginCache.emplace(1, boost::move(foo));
But... if you have std::map::emplace then your compiler supports c++11, then you may consider using std::unique_ptr instead of boost.
P.S.
g++ 3.4.6 is +10 years old and is likely to break something in recent boost versions. Is there any specific reason to use an outdated compiler?

Related

warning: operator delete called on unallocated object

I'm trying to compile the following code (this is a minimal example), but I get a warning I can't figure out:
#include <string>
#include <variant>
#include <vector>
struct Bar {
std::wstring x = L"";
};
Bar Foo() {
std::variant<std::vector<int>, Bar> tmp = Bar();
if (std::holds_alternative<Bar>(tmp)) return std::move(std::get<Bar>(tmp));
return Bar();
}
I'm trying to build this with g++ -std=c++20 -Wall -Wextra -O2 /tmp/test.cc -c
I get the following warning:
In file included from /usr/include/x86_64-linux-gnu/c++/12/bits/c++allocator.h:33,
from /usr/include/c++/12/bits/allocator.h:46,
from /usr/include/c++/12/string:41,
from /tmp/test.cc:1:
In member function ‘void std::__new_allocator<_Tp>::deallocate(_Tp*, size_type) [with _Tp = int]’,
inlined from ‘constexpr void std::allocator< <template-parameter-1-1> >::deallocate(_Tp*, std::size_t) [with _Tp = int]’ at /usr/include/c++/12/bits/allocator.h:200:35,
inlined from ‘static constexpr void std::allocator_traits<std::allocator<_CharT> >::deallocate(allocator_type&, pointer, size_type) [with _Tp = int]’ at /usr/include/c++/12/bits/alloc_traits.h:496:23,
inlined from ‘constexpr void std::_Vector_base<_Tp, _Alloc>::_M_deallocate(pointer, std::size_t) [with _Tp = int; _Alloc = std::allocator<int>]’ at /usr/include/c++/12/bits/stl_vector.h:387:19,
inlined from ‘constexpr std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = int; _Alloc = std::allocator<int>]’ at /usr/include/c++/12/bits/stl_vector.h:366:15,
inlined from ‘constexpr std::vector<_Tp, _Alloc>::~vector() [with _Tp = int; _Alloc = std::allocator<int>]’ at /usr/include/c++/12/bits/stl_vector.h:733:7,
inlined from ‘constexpr void std::destroy_at(_Tp*) [with _Tp = vector<int>]’ at /usr/include/c++/12/bits/stl_construct.h:88:18,
inlined from ‘constexpr void std::_Destroy(_Tp*) [with _Tp = vector<int>]’ at /usr/include/c++/12/bits/stl_construct.h:149:22,
inlined from ‘std::__detail::__variant::_Variant_storage<false, std::vector<int, std::allocator<int> >, Bar>::_M_reset()::<lambda(auto:11&&)> mutable [with auto:11 = std::vector<int>&]’ at /usr/include/c++/12/variant:472:19,
inlined from ‘constexpr _Res std::__invoke_impl(__invoke_other, _Fn&&, _Args&& ...) [with _Res = void; _Fn = __detail::__variant::_Variant_storage<false, vector<int, allocator<int> >, Bar>::_M_reset()::<lambda(auto:11&&)>; _Args = {vector<int, allocator<int> >&}]’ at /usr/include/c++/12/bits/invoke.h:61:36,
inlined from ‘constexpr std::enable_if_t<is_invocable_r_v<_Res, _Callable, _Args ...>, _Res> std::__invoke_r(_Callable&&, _Args&& ...) [with _Res = void; _Callable = __detail::__variant::_Variant_storage<false, vector<int, allocator<int> >, Bar>::_M_reset()::<lambda(auto:11&&)>; _Args = {vector<int, allocator<int> >&}]’ at /usr/include/c++/12/bits/invoke.h:111:28,
inlined from ‘static constexpr decltype(auto) std::__detail::__variant::__gen_vtable_impl<std::__detail::__variant::_Multi_array<_Result_type (*)(_Visitor, _Variants ...)>, std::integer_sequence<long unsigned int, __indices ...> >::__visit_invoke(_Visitor&&, _Variants ...) [with _Result_type = void; _Visitor = std::__detail::__variant::_Variant_storage<false, std::vector<int, std::allocator<int> >, Bar>::_M_reset()::<lambda(auto:11&&)>&&; _Variants = {std::variant<std::vector<int, std::allocator<int> >, Bar>&}; long unsigned int ...__indices = {0}]’ at /usr/include/c++/12/variant:1035:40,
inlined from ‘constexpr decltype(auto) std::__do_visit(_Visitor&&, _Variants&& ...) [with _Result_type = void; _Visitor = __detail::__variant::_Variant_storage<false, vector<int, allocator<int> >, Bar>::_M_reset()::<lambda(auto:11&&)>; _Variants = {variant<vector<int, allocator<int> >, Bar>&}]’ at /usr/include/c++/12/variant:1783:5,
inlined from ‘constexpr void std::__detail::__variant::_Variant_storage<false, _Types ...>::_M_reset() [with _Types = {std::vector<int, std::allocator<int> >, Bar}]’ at /usr/include/c++/12/variant:470:23,
inlined from ‘constexpr std::__detail::__variant::_Variant_storage<false, _Types ...>::~_Variant_storage() [with _Types = {std::vector<int, std::allocator<int> >, Bar}]’ at /usr/include/c++/12/variant:480:17,
inlined from ‘constexpr std::__detail::__variant::_Copy_ctor_base<false, std::vector<int, std::allocator<int> >, Bar>::~_Copy_ctor_base()’ at /usr/include/c++/12/variant:554:12,
inlined from ‘constexpr std::__detail::__variant::_Move_ctor_base<false, std::vector<int, std::allocator<int> >, Bar>::~_Move_ctor_base()’ at /usr/include/c++/12/variant:591:12,
inlined from ‘constexpr std::__detail::__variant::_Copy_assign_base<false, std::vector<int, std::allocator<int> >, Bar>::~_Copy_assign_base()’ at /usr/include/c++/12/variant:629:12,
inlined from ‘constexpr std::__detail::__variant::_Move_assign_base<false, std::vector<int, std::allocator<int> >, Bar>::~_Move_assign_base()’ at /usr/include/c++/12/variant:681:12,
inlined from ‘constexpr std::__detail::__variant::_Variant_base<std::vector<int, std::allocator<int> >, Bar>::~_Variant_base()’ at /usr/include/c++/12/variant:735:12,
inlined from ‘constexpr std::variant<_Types>::~variant() [with _Types = {std::vector<int, std::allocator<int> >, Bar}]’ at /usr/include/c++/12/variant:1407:28,
inlined from ‘Bar Foo()’ at /tmp/test.cc:13:1:
/usr/include/c++/12/bits/new_allocator.h:158:33: warning: ‘void operator delete(void*, std::size_t)’ called on unallocated object ‘tmp’ [-Wfree-nonheap-object]
158 | _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n));
| ^
/tmp/test.cc: In function ‘Bar Foo()’:
/tmp/test.cc:10:39: note: declared here
10 | std::variant<std::vector<int>, Bar> tmp = Bar();
| ^~~
g++ --version says g++ (Debian 12.2.0-10) 12.2.0
I know this code, as is, doesn't make that much sense; but it also shouldn't have this problem: this is a minimal example that exhibits this warning, of a much more complex function.
Strangely, the warning disappears if I do any of the following:
Change Bar::x to be a std::string.
Change tmp to be std::variant<int, Bar> (rather than having a std::vector<int> as the first type).
Remove g++ command-line flag -O2 (i.e., compile with g++ -std=c++20 -Wall -Wextra -O2 /tmp/test.cc -c).
Why would any of these changes make the warning go away!?
If I build this with --std=c++17, the problem remains.
The -Wfree-nonheap-object flag of gcc has a series of false positives bugs, among which bug 99098 is used to record these meta-bugs.
The bug in your example is similar to bug 108088 and has been listed, which issues a false positive warning message since gcc-12.

No match found for operator= (find value in vector<string>)

I'm clearly missing something here, but what?
Definition (... denotes valid code, not actual three points):
class CrmxFile {
private:
const std::vector<std::string> validValues;
int value;
public:
void setValue(std::string _value);
...
}
std::vector<std::string> CrmxFile = {...};
In the code I have this:
void Crmx::SetValue(std::string _value) {
std::vector<std::string>::iterator idx;
if((idx = std::find(validValues.begin(), validValues.end(), _value)) == validValues.end()) {
value = 0;
}
else {
value = idx - validValues.begin();
}
}
I compile this with gcc -c -std=c++0x and I get this error:
CrmxFile.cpp: In member function ‘void CrmxFile::SetValue(std::string)’:
CrmxFile.cpp:24:64: error: no match for ‘operator=’ in ‘idx = std::find [with _IIter = __gnu_cxx::__normal_iterator<const std::basic_string<char>*, std::vector<std::basic_string<char> > >, _Tp = std::basic_string<char>](Id3V1::validValues.std::vector<_Tp, _Alloc>::begin [with _Tp = std::basic_string<char>, _Alloc = std::allocator<std::basic_string<char> >, std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const std::basic_string<char>*, std::vector<std::basic_string<char> > >, typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::const_pointer = const std::basic_string<char>*](), Id3V1::validValues.std::vector<_Tp, _Alloc>::end [with _Tp = std::basic_string<char>, _Alloc = std::allocator<std::basic_string<char> >, std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const std::basic_string<char>*, std::vector<std::basic_string<char> > >, typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::const_pointer = const std::basic_string<char>*](), (*(const std::basic_string<char>*)(& _value)))’
CrmxFile.cpp:24:64: note: candidates are:
/usr/include/c++/4.6/bits/stl_iterator.h:702:11: note: __gnu_cxx::__normal_iterator<std::basic_string<char>*, std::vector<std::basic_string<char> > >& __gnu_cxx::__normal_iterator<std::basic_string<char>*, std::vector<std::basic_string<char> > >::operator=(const __gnu_cxx::__normal_iterator<std::basic_string<char>*, std::vector<std::basic_string<char> > >&)
/usr/include/c++/4.6/bits/stl_iterator.h:702:11: note: no known conversion for argument 1 from ‘__gnu_cxx::__normal_iterator<const std::basic_string<char>*, std::vector<std::basic_string<char> > >’ to ‘const __gnu_cxx::__normal_iterator<std::basic_string<char>*, std::vector<std::basic_string<char> > >&’
/usr/include/c++/4.6/bits/stl_iterator.h:702:11: note: __gnu_cxx::__normal_iterator<std::basic_string<char>*, std::vector<std::basic_string<char> > >& __gnu_cxx::__normal_iterator<std::basic_string<char>*, std::vector<std::basic_string<char> > >::operator=(__gnu_cxx::__normal_iterator<std::basic_string<char>*, std::vector<std::basic_string<char> > >&&)
/usr/include/c++/4.6/bits/stl_iterator.h:702:11: note: no known conversion for argument 1 from ‘__gnu_cxx::__normal_iterator<const std::basic_string<char>*, std::vector<std::basic_string<char> > >’ to ‘__gnu_cxx::__normal_iterator<std::basic_string<char>*, std::vector<std::basic_string<char> > >&&’
What am I missing? Or, alternatively, is there a better way of finding the index of a given value in a vector?
idx has to be a const_iterator since validValues is a const vector<...>.
std::vector<std::string>::const_iterator idx;
Since validValues is const, begin(), end(), and therefore this instantiation of std::find, all return std::vector<std::string>::const_iterator, not std::vector<std::string>::iterator. For const-safety, a const_iterator cannot convert to an iterator.
validValues is defined as const std::vector<std::string>. Therefore begin() and end() will return const_iterator, but you are trying to assign the result to a iterator. Converting a const_iterator to an iterator would break const correctness (since you could then go on and change the underlying object) and is therefore not allowed.
Change the definition of idx to be std::vector<std::string>::const_iterator and it should work.
"What am I missing?"
Is yours first validValues invalid?
I suggest:
void Crmx::SetValue(std::string _value) {
value = std::find(validValues.begin(), validValues.end(), _value) - validValues.begin();
}
and use the validValues.size as invalid value, not 0

Errors building STLPort

I'm trying to use STLPort in my project, and when I follow the directions in INSTALL.unixes I get compile errors.
I ran ./configure, then make, the output is below. I'm using make 3.81 and gcc 4.6.1 on Ubuntu.
Edit: I tried adding --with-extra-cxxflags="-std=c++ox" and I get a different and smaller set of errors, listed below.
In file included from ../stlport/memory:45:0,
from reachable.cc:16:
../stlport/stl/_shared_ptr.h:377:43: error: function definition does not declare parameters
../stlport/stl/_shared_ptr.h:421:39: error: declaration of ‘operator=’ as non-function
../stlport/stl/_shared_ptr.h:421:26: error: expected ‘;’ at end of member declaration
../stlport/stl/_shared_ptr.h:421:39: error: function definition does not declare parameters
../stlport/stl/_shared_ptr.h:463:17: error: ‘nullptr_t’ has not been declared
../stlport/stl/_shared_ptr.h:536:43: error: function definition does not declare parameters
../stlport/stl/_shared_ptr.h:552:39: error: declaration of ‘operator=’ as non-function
../stlport/stl/_shared_ptr.h:552:26: error: expected ‘;’ at end of member declaration
../stlport/stl/_shared_ptr.h:552:39: error: function definition does not declare parameters
../stlport/stl/_shared_ptr.h:591:17: error: ‘nullptr_t’ has not been declared
In file included from ../stlport/memory:45:0,
from reachable.cc:16:
../stlport/stl/_shared_ptr.h:643:45: error: ‘nullptr_t’ has not been declared
../stlport/stl/_shared_ptr.h:647:18: error: declaration of ‘operator==’ as non-function
../stlport/stl/_shared_ptr.h:647:18: error: ‘nullptr_t’ was not declared in this scope
../stlport/stl/_shared_ptr.h:647:18: note: suggested alternative:
/usr/include/c++/4.6/i686-linux-gnu/./bits/c++config.h:159:29: note: ‘std::nullptr_t’
../stlport/stl/_shared_ptr.h:647:29: error: expected primary-expression before ‘const’
../stlport/stl/_shared_ptr.h:647:50: error: expected primary-expression before ‘>’ token
../stlport/stl/_shared_ptr.h:647:53: error: ‘x’ was not declared in this scope
../stlport/stl/_shared_ptr.h:651:45: error: ‘nullptr_t’ has not been declared
../stlport/stl/_shared_ptr.h:655:18: error: declaration of ‘operator!=’ as non-function
../stlport/stl/_shared_ptr.h:655:18: error: ‘nullptr_t’ was not declared in this scope
../stlport/stl/_shared_ptr.h:655:18: note: suggested alternative:
/usr/include/c++/4.6/i686-linux-gnu/./bits/c++config.h:159:29: note: ‘std::nullptr_t’
../stlport/stl/_shared_ptr.h:655:29: error: expected primary-expression before ‘const’
../stlport/stl/_shared_ptr.h:655:50: error: expected primary-expression before ‘>’ token
../stlport/stl/_shared_ptr.h:655:53: error: ‘x’ was not declared in this scope
../stlport/stl/_shared_ptr.h:660:44: error: ‘nullptr_t’ has not been declared
../stlport/stl/_shared_ptr.h:665:17: error: declaration of ‘operator<’ as non-function
../stlport/stl/_shared_ptr.h:665:17: error: ‘nullptr_t’ was not declared in this scope
../stlport/stl/_shared_ptr.h:665:17: note: suggested alternative:
/usr/include/c++/4.6/i686-linux-gnu/./bits/c++config.h:159:29: note: ‘std::nullptr_t’
../stlport/stl/_shared_ptr.h:665:28: error: expected primary-expression before ‘const’
../stlport/stl/_shared_ptr.h:665:49: error: expected primary-expression before ‘>’ token
../stlport/stl/_shared_ptr.h:665:52: error: ‘x’ was not declared in this scope
../stlport/stl/_shared_ptr.h:669:44: error: ‘nullptr_t’ has not been declared
../stlport/stl/_shared_ptr.h:673:17: error: declaration of ‘operator>’ as non-function
../stlport/stl/_shared_ptr.h:673:17: error: ‘nullptr_t’ was not declared in this scope
../stlport/stl/_shared_ptr.h:673:17: note: suggested alternative:
/usr/include/c++/4.6/i686-linux-gnu/./bits/c++config.h:159:29: note: ‘std::nullptr_t’
../stlport/stl/_shared_ptr.h:673:28: error: expected primary-expression before ‘const’
../stlport/stl/_shared_ptr.h:673:49: error: expected primary-expression before ‘>’ token
../stlport/stl/_shared_ptr.h:673:52: error: ‘x’ was not declared in this scope
../stlport/stl/_shared_ptr.h:677:45: error: ‘nullptr_t’ has not been declared
../stlport/stl/_shared_ptr.h:681:18: error: declaration of ‘operator<=’ as non-function
../stlport/stl/_shared_ptr.h:681:18: error: ‘nullptr_t’ was not declared in this scope
../stlport/stl/_shared_ptr.h:681:18: note: suggested alternative:
/usr/include/c++/4.6/i686-linux-gnu/./bits/c++config.h:159:29: note: ‘std::nullptr_t’
../stlport/stl/_shared_ptr.h:681:29: error: expected primary-expression before ‘const’
../stlport/stl/_shared_ptr.h:681:50: error: expected primary-expression before ‘>’ token
../stlport/stl/_shared_ptr.h:681:53: error: ‘x’ was not declared in this scope
../stlport/stl/_shared_ptr.h:685:45: error: ‘nullptr_t’ has not been declared
../stlport/stl/_shared_ptr.h:689:18: error: declaration of ‘operator>=’ as non-function
../stlport/stl/_shared_ptr.h:689:18: error: ‘nullptr_t’ was not declared in this scope
../stlport/stl/_shared_ptr.h:689:18: note: suggested alternative:
/usr/include/c++/4.6/i686-linux-gnu/./bits/c++config.h:159:29: note: ‘std::nullptr_t’
../stlport/stl/_shared_ptr.h:689:29: error: expected primary-expression before ‘const’
../stlport/stl/_shared_ptr.h:689:50: error: expected primary-expression before ‘>’ token
../stlport/stl/_shared_ptr.h:689:53: error: ‘x’ was not declared in this scope
../stlport/stl/_shared_ptr.h:775:26: error: expected ‘)’ before ‘,’ token
../stlport/stl/_shared_ptr.h:790:26: error: expected ‘)’ before ‘,’ token
../stlport/stl/_shared_ptr.h:917:43: error: function definition does not declare parameters
../stlport/stl/_shared_ptr.h:1160:26: error: expected ‘)’ before ‘,’ token
../stlport/stl/_shared_ptr.h:1175:26: error: expected ‘)’ before ‘,’ token
../stlport/stl/_shared_ptr.h:1296:43: error: function definition does not declare parameters
../stlport/stl/_shared_ptr.h:1553:42: error: ‘nullptr_t’ has not been declared
../stlport/stl/_shared_ptr.h:1557:18: error: declaration of ‘operator==’ as non-function
../stlport/stl/_shared_ptr.h:1557:18: error: ‘nullptr_t’ was not declared in this scope
../stlport/stl/_shared_ptr.h:1557:18: note: suggested alternative:
/usr/include/c++/4.6/i686-linux-gnu/./bits/c++config.h:159:29: note: ‘std::nullptr_t’
../stlport/stl/_shared_ptr.h:1557:29: error: expected primary-expression before ‘const’
../stlport/stl/_shared_ptr.h:1561:42: error: ‘nullptr_t’ has not been declared
../stlport/stl/_shared_ptr.h:1565:18: error: declaration of ‘operator!=’ as non-function
../stlport/stl/_shared_ptr.h:1565:18: error: ‘nullptr_t’ was not declared in this scope
../stlport/stl/_shared_ptr.h:1565:18: note: suggested alternative:
/usr/include/c++/4.6/i686-linux-gnu/./bits/c++config.h:159:29: note: ‘std::nullptr_t’
../stlport/stl/_shared_ptr.h:1565:29: error: expected primary-expression before ‘const’
../stlport/stl/_shared_ptr.h:1569:41: error: ‘nullptr_t’ has not been declared
../stlport/stl/_shared_ptr.h:1573:17: error: declaration of ‘operator<’ as non-function
../stlport/stl/_shared_ptr.h:1573:17: error: ‘nullptr_t’ was not declared in this scope
../stlport/stl/_shared_ptr.h:1573:17: note: suggested alternative:
/usr/include/c++/4.6/i686-linux-gnu/./bits/c++config.h:159:29: note: ‘std::nullptr_t’
../stlport/stl/_shared_ptr.h:1573:28: error: expected primary-expression before ‘const’
../stlport/stl/_shared_ptr.h:1577:42: error: ‘nullptr_t’ has not been declared
../stlport/stl/_shared_ptr.h:1581:18: error: declaration of ‘operator<=’ as non-function
../stlport/stl/_shared_ptr.h:1581:18: error: ‘nullptr_t’ was not declared in this scope
../stlport/stl/_shared_ptr.h:1581:18: note: suggested alternative:
/usr/include/c++/4.6/i686-linux-gnu/./bits/c++config.h:159:29: note: ‘std::nullptr_t’
../stlport/stl/_shared_ptr.h:1581:29: error: expected primary-expression before ‘const’
../stlport/stl/_shared_ptr.h:1585:41: error: ‘nullptr_t’ has not been declared
../stlport/stl/_shared_ptr.h:1589:17: error: declaration of ‘operator>’ as non-function
../stlport/stl/_shared_ptr.h:1589:17: error: ‘nullptr_t’ was not declared in this scope
../stlport/stl/_shared_ptr.h:1589:17: note: suggested alternative:
/usr/include/c++/4.6/i686-linux-gnu/./bits/c++config.h:159:29: note: ‘std::nullptr_t’
../stlport/stl/_shared_ptr.h:1589:28: error: expected primary-expression before ‘const’
../stlport/stl/_shared_ptr.h:1593:42: error: ‘nullptr_t’ has not been declared
../stlport/stl/_shared_ptr.h:1597:18: error: declaration of ‘operator>=’ as non-function
../stlport/stl/_shared_ptr.h:1597:18: error: ‘nullptr_t’ was not declared in this scope
../stlport/stl/_shared_ptr.h:1597:18: note: suggested alternative:
/usr/include/c++/4.6/i686-linux-gnu/./bits/c++config.h:159:29: note: ‘std::nullptr_t’
../stlport/stl/_shared_ptr.h:1597:29: error: expected primary-expression before ‘const’
In file included from ../stlport/stl/_hashtable.h:541:0,
from ../stlport/stl/_unordered_map.h:24,
from ../stlport/unordered_map:28,
from reachable.cc:17:
../stlport/stl/_hashtable.c: In member function ‘stlp_std::pair<stlp_std::priv::_Ht_iterator<typename stlp_std::forward_list<_Val, _All>::iterator, typename _Traits::_NonConstTraits>, bool> stlp_std::hashtable<_Val, _Key, _HF, _Traits, _ExK, _EqK, _All>::insert_unique_noresize(const value_type&) [with _Val = stlp_std::pair<void* const, long unsigned int>, _Key = void*, _HF = stlp_std::hash<void*>, _Traits = stlp_std::priv::_UnorderedMapTraitsT<stlp_std::pair<void* const, long unsigned int> >, _ExK = stlp_std::priv::_Select1st<stlp_std::pair<void* const, long unsigned int> >, _EqK = stlp_std::equal_to<void*>, _All = stlp_std::allocator<stlp_std::pair<void* const, long unsigned int> >, typename _Traits::_NonConstTraits = stlp_std::priv::_NonLocalUnorderedMapTraitsT<stlp_std::pair<void* const, long unsigned int> >, typename stlp_std::forward_list<_Val, _All>::iterator = stlp_std::priv::_Slist_iterator<stlp_std::pair<void* const, long unsigned int>, stlp_std::_Nonconst_traits<stlp_std::pair<void* const, long unsigned int> > >, stlp_std::hashtable<_Val, _Key, _HF, _Traits, _ExK, _EqK, _All>::value_type = stlp_std::pair<void* const, long unsigned int>]’:
../stlport/stl/_hashtable.c:251:41: instantiated from ‘stlp_std::hashtable<_Val, _Key, _HF, _Traits, _ExK, _EqK, _All>::reference stlp_std::hashtable<_Val, _Key, _HF, _Traits, _ExK, _EqK, _All>::_M_insert(const value_type&) [with _Val = stlp_std::pair<void* const, long unsigned int>, _Key = void*, _HF = stlp_std::hash<void*>, _Traits = stlp_std::priv::_UnorderedMapTraitsT<stlp_std::pair<void* const, long unsigned int> >, _ExK = stlp_std::priv::_Select1st<stlp_std::pair<void* const, long unsigned int> >, _EqK = stlp_std::equal_to<void*>, _All = stlp_std::allocator<stlp_std::pair<void* const, long unsigned int> >, stlp_std::hashtable<_Val, _Key, _HF, _Traits, _ExK, _EqK, _All>::reference = stlp_std::pair<void* const, long unsigned int>&, stlp_std::hashtable<_Val, _Key, _HF, _Traits, _ExK, _EqK, _All>::value_type = stlp_std::pair<void* const, long unsigned int>]’
../stlport/stl/_unordered_map.h:130:22: instantiated from ‘_Tp& stlp_std::unordered_map<_Key, _Tp, _HashFcn, _EqualKey, _Alloc>::operator[](const _KT&) [with _KT = void*, _Key = void*, _Tp = long unsigned int, _HashFcn = stlp_std::hash<void*>, _EqualKey = stlp_std::equal_to<void*>, _Alloc = stlp_std::allocator<stlp_std::pair<void* const, long unsigned int> >]’
reachable.cc:45:27: instantiated from here
../stlport/stl/_hashtable.c:206:59: error: use of deleted function ‘stlp_std::pair<_T1, _T2>::pair(stlp_std::pair<_T1, _T2>&&) [with _T1 = stlp_std::priv::_Ht_iterator<stlp_std::priv::_Slist_iterator<stlp_std::pair<void* const, long unsigned int>, stlp_std::_Nonconst_traits<stlp_std::pair<void* const, long unsigned int> > >, stlp_std::priv::_NonLocalUnorderedMapTraitsT<stlp_std::pair<void* const, long unsigned int> > >, _T2 = bool, stlp_std::pair<_T1, _T2> = stlp_std::pair<stlp_std::priv::_Ht_iterator<stlp_std::priv::_Slist_iterator<stlp_std::pair<void* const, long unsigned int>, stlp_std::_Nonconst_traits<stlp_std::pair<void* const, long unsigned int> > >, stlp_std::priv::_NonLocalUnorderedMapTraitsT<stlp_std::pair<void* const, long unsigned int> > >, bool>]’
In file included from ../stlport/stl/_alloc.h:53:0,
from ../stlport/memory:30,
from reachable.cc:16:
../stlport/utility:140:3: error: ‘stlp_std::pair<_T1, _T2>::pair(stlp_std::pair<_T1, _T2>&&) [with _T1 = stlp_std::priv::_Ht_iterator<stlp_std::priv::_Slist_iterator<stlp_std::pair<void* const, long unsigned int>, stlp_std::_Nonconst_traits<stlp_std::pair<void* const, long unsigned int> > >, stlp_std::priv::_NonLocalUnorderedMapTraitsT<stlp_std::pair<void* const, long unsigned int> > >, _T2 = bool, stlp_std::pair<_T1, _T2> = stlp_std::pair<stlp_std::priv::_Ht_iterator<stlp_std::priv::_Slist_iterator<stlp_std::pair<void* const, long unsigned int>, stlp_std::_Nonconst_traits<stlp_std::pair<void* const, long unsigned int> > >, stlp_std::priv::_NonLocalUnorderedMapTraitsT<stlp_std::pair<void* const, long unsigned int> > >, bool>]’ is implicitly deleted because the default definition would be ill-formed:
../stlport/utility:140:3: error: non-static data member ‘stlp_std::pair<stlp_std::priv::_Ht_iterator<stlp_std::priv::_Slist_iterator<stlp_std::pair<void* const, long unsigned int>, stlp_std::_Nonconst_traits<stlp_std::pair<void* const, long unsigned int> > >, stlp_std::priv::_NonLocalUnorderedMapTraitsT<stlp_std::pair<void* const, long unsigned int> > >, bool>::first’ does not have a move constructor or trivial copy constructor
In file included from ../stlport/stl/_hashtable.h:541:0,
from ../stlport/stl/_unordered_map.h:24,
from ../stlport/unordered_map:28,
from reachable.cc:17:
../stlport/stl/_hashtable.c:251:41: instantiated from ‘stlp_std::hashtable<_Val, _Key, _HF, _Traits, _ExK, _EqK, _All>::reference stlp_std::hashtable<_Val, _Key, _HF, _Traits, _ExK, _EqK, _All>::_M_insert(const value_type&) [with _Val = stlp_std::pair<void* const, long unsigned int>, _Key = void*, _HF = stlp_std::hash<void*>, _Traits = stlp_std::priv::_UnorderedMapTraitsT<stlp_std::pair<void* const, long unsigned int> >, _ExK = stlp_std::priv::_Select1st<stlp_std::pair<void* const, long unsigned int> >, _EqK = stlp_std::equal_to<void*>, _All = stlp_std::allocator<stlp_std::pair<void* const, long unsigned int> >, stlp_std::hashtable<_Val, _Key, _HF, _Traits, _ExK, _EqK, _All>::reference = stlp_std::pair<void* const, long unsigned int>&, stlp_std::hashtable<_Val, _Key, _HF, _Traits, _ExK, _EqK, _All>::value_type = stlp_std::pair<void* const, long unsigned int>]’
../stlport/stl/_unordered_map.h:130:22: instantiated from ‘_Tp& stlp_std::unordered_map<_Key, _Tp, _HashFcn, _EqualKey, _Alloc>::operator[](const _KT&) [with _KT = void*, _Key = void*, _Tp = long unsigned int, _HashFcn = stlp_std::hash<void*>, _EqualKey = stlp_std::equal_to<void*>, _Alloc = stlp_std::allocator<stlp_std::pair<void* const, long unsigned int> >]’
reachable.cc:45:27: instantiated from here
../stlport/stl/_hashtable.c:216:54: error: use of deleted function ‘stlp_std::pair<_T1, _T2>::pair(stlp_std::pair<_T1, _T2>&&) [with _T1 = stlp_std::priv::_Ht_iterator<stlp_std::priv::_Slist_iterator<stlp_std::pair<void* const, long unsigned int>, stlp_std::_Nonconst_traits<stlp_std::pair<void* const, long unsigned int> > >, stlp_std::priv::_NonLocalUnorderedMapTraitsT<stlp_std::pair<void* const, long unsigned int> > >, _T2 = bool, stlp_std::pair<_T1, _T2> = stlp_std::pair<stlp_std::priv::_Ht_iterator<stlp_std::priv::_Slist_iterator<stlp_std::pair<void* const, long unsigned int>, stlp_std::_Nonconst_traits<stlp_std::pair<void* const, long unsigned int> > >, stlp_std::priv::_NonLocalUnorderedMapTraitsT<stlp_std::pair<void* const, long unsigned int> > >, bool>]’
../stlport/stl/_hashtable.c:251:41: instantiated from ‘stlp_std::hashtable<_Val, _Key, _HF, _Traits, _ExK, _EqK, _All>::reference stlp_std::hashtable<_Val, _Key, _HF, _Traits, _ExK, _EqK, _All>::_M_insert(const value_type&) [with _Val = stlp_std::pair<void* const, long unsigned int>, _Key = void*, _HF = stlp_std::hash<void*>, _Traits = stlp_std::priv::_UnorderedMapTraitsT<stlp_std::pair<void* const, long unsigned int> >, _ExK = stlp_std::priv::_Select1st<stlp_std::pair<void* const, long unsigned int> >, _EqK = stlp_std::equal_to<void*>, _All = stlp_std::allocator<stlp_std::pair<void* const, long unsigned int> >, stlp_std::hashtable<_Val, _Key, _HF, _Traits, _ExK, _EqK, _All>::reference = stlp_std::pair<void* const, long unsigned int>&, stlp_std::hashtable<_Val, _Key, _HF, _Traits, _ExK, _EqK, _All>::value_type = stlp_std::pair<void* const, long unsigned int>]’
../stlport/stl/_unordered_map.h:130:22: instantiated from ‘_Tp& stlp_std::unordered_map<_Key, _Tp, _HashFcn, _EqualKey, _Alloc>::operator[](const _KT&) [with _KT = void*, _Key = void*, _Tp = long unsigned int, _HashFcn = stlp_std::hash<void*>, _EqualKey = stlp_std::equal_to<void*>, _Alloc = stlp_std::allocator<stlp_std::pair<void* const, long unsigned int> >]’
reachable.cc:45:27: instantiated from here
../stlport/stl/_hashtable.c:219:67: error: use of deleted function ‘stlp_std::pair<_T1, _T2>::pair(stlp_std::pair<_T1, _T2>&&) [with _T1 = stlp_std::priv::_Ht_iterator<stlp_std::priv::_Slist_iterator<stlp_std::pair<void* const, long unsigned int>, stlp_std::_Nonconst_traits<stlp_std::pair<void* const, long unsigned int> > >, stlp_std::priv::_NonLocalUnorderedMapTraitsT<stlp_std::pair<void* const, long unsigned int> > >, _T2 = bool, stlp_std::pair<_T1, _T2> = stlp_std::pair<stlp_std::priv::_Ht_iterator<stlp_std::priv::_Slist_iterator<stlp_std::pair<void* const, long unsigned int>, stlp_std::_Nonconst_traits<stlp_std::pair<void* const, long unsigned int> > >, stlp_std::priv::_NonLocalUnorderedMapTraitsT<stlp_std::pair<void* const, long unsigned int> > >, bool>]’
make[1]: *** [obj/gcc/so/reachable.o] Error 1
make: *** [release-shared] Error 2
It turns out the source I got my copy of STLPort from, git://stlport.git.sourceforge.net/gitroot/stlport/stlport, is much more bleeding edge than I thought. If I grab the stable build from SourceForge it compiles fine.

priority queue in stl

I followed the article to code a hanffman coding method using stl's priority_queue, however I think there are some bugs in the final code or it's not updated. The main problem is the declaration of the priority_queue, I believe it should take three parameters like: priority_queue< node, vector, greater > q, instead of priority_queue, greater > q.
However, even with this changes, the gcc compiler still give the errors like:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_function.h: In member function ‘bool std::greater<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = node]’:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_heap.h:279: instantiated from ‘void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<node*, std::vector<node, std::allocator<node> > >, _Distance = long int, _Tp = node, _Compare = std::greater<node>]’
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_heap.h:404: instantiated from ‘void std::make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<node*, std::vector<node, std::allocator<node> > >, _Compare = std::greater<node>]’
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_queue.h:367: instantiated from ‘std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const _Compare&, const _Sequence&) [with _Tp = node, _Sequence = std::vector<node, std::allocator<node> >, _Compare = std::greater<node>]’ hanffman.cpp:119: instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_function.h:218: error: no match for ‘operator>’ in ‘__x > __y’
which I don't understand. The full code is available here
You need to define an operator>() for your class because you are using std::greater<> as the comparison in the priority_queue. The only operator I saw in the code was operator<().
You are missing the definition of the > operator for node (you only define the < operator).

Problem compiling stl map insert

I'm having trouble compiling the following code:
typedef std::map<mUUID, block_ptr_t> BlockMap;
BlockMap _store;
std::pair< BlockMap::iterator, bool > it;
it = _store.insert(hint, std::make_pair(entry.block_uid, block));
The error is:
error: no match for ‘operator=’ in ‘it = BlockStore::_store.std::map<_Key, _Tp, _Compare, _Alloc>::insert [with _Key = mUUID, _Tp = Block*, _Compare = std::less<mUUID>, _Alloc = std::allocator<std::pair<const mUUID, Block*> >](lb, ((const std::pair<const mUUID, Block*>&)(& std::pair<const mUUID, Block*>(((const std::pair<mUUID, Block*>&)((const std::pair<mUUID, Block*>*)(& std::make_pair(_T1, _T2) [with _T1 = mUUID, _T2 = Block*](block))))))))’
/usr/include/c++/4.4/bits/stl_pair.h:68: note: candidates are: std::pair<std::_Rb_tree_iterator<std::pair<const mUUID, Block*> >, bool>& std::pair<std::_Rb_tree_iterator<std::pair<const mUUID, Block*> >, bool>::operator=(const std::pair<std::_Rb_tree_iterator<std::pair<const mUUID, Block*> >, bool>&)
It seems to be related to the assignment because if I don't assign it to "it" it compiles without error.
The version of insert that takes a hint returns only an iterator, not a pair.
First of all, your example is incomplete - _store is defined nowhere.
Second, it seems you are trying to assign an iterator to a std::pair - why do you need a pair, anyway?
The following should work, provided that _store is of type BlockMap:
BlockMap::iterator it;
it = _store.insert(std::make_pair(entry.block_uid, block));