I have not worked with c++ in a few years and am struggling with implementing a boost multi_index container. I've generated a toy that demonstrates my problem here: http://cpp.sh/6q4nb, and (after some typing) I've recreated that code here:
#include <iostream>
#include <string>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/identity.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/mem_fun.hpp>
class Placeholder {
public:
const uint64_t& getPlaceholderTime( void ) const { return ph_time; }
const std::string& getPlaceholderId( void ) const { return ph_id; }
private:
uint64_t ph_time;
std::string ph_id;
};
struct IndexByPlaceholderId { };
typedef boost::multi_index_container<
Placeholder,
boost::multi_index::indexed_by
<boost::multi_index::ordered_non_unique< boost::multi_index::identity<Placeholder> >
,boost::multi_index::ordered_non_unique<
boost::multi_index::const_mem_fun<
Placeholder,
const uint64_t&,
&Placeholder::getPlaceholderTime
>
>
,boost::multi_index::ordered_non_unique<
boost::multi_index::tag<IndexByPlaceholderId>,
boost::multi_index::const_mem_fun<
Placeholder,
const std::string&,
&Placeholder::getPlaceholderId
>
>
>
> currentPlaceholderDatabase;
int main()
{
currentPlaceholderDatabase currentDb;
std::string someString = "something";
volatile auto result = currentDb.get<IndexByPlaceholderId>().find( someString );
if( result == currentDb.get<IndexByPlaceholderId>().end() )
{
std::cout << "NOT FOUND\n";
}
else
{
std::cout << "FOUND!!\n";
}
}
Essentially, I'm searching for an element using find() and then testing if that element is found or not using operator==. The search I'm doing is using index tagging as explained in the boost documentation. If it is required that I generate an operator== for this container, can someone demonstrate how to do so as I can't find a clear example in the documentation?
The error I get is:
57:14: error: no match for 'operator==' (operand types are 'volatile boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<Placeholder, std::allocator<Placeholder> > > >' and 'boost::multi_index::detail::ordered_index<boost::multi_index::const_mem_fun<Placeholder, const std::basic_string<char>&, &Placeholder::getPlaceholderId>, std::less<const std::basic_string<char> >, boost::multi_index::detail::nth_layer<3, Placeholder, boost::multi_index::indexed_by<boost::multi_index::ordered_non_unique<boost::multi_index::identity<Placeholder> >, boost::multi_index::ordered_non_unique<boost::multi_index::const_mem_fun<Placeholder, const long unsigned int&, &Placeholder::getPlaceholderTime> >, boost::multi_index::ordered_non_unique<boost::multi_index::tag<IndexByPlaceholderId>, boost::multi_index::const_mem_fun<Placeholder, const std::basic_string<char>&, &Placeholder::getPlaceholderId> > >, std::allocator<Placeholder> >, boost::mpl::v_item<IndexByPlaceholderId, boost::mpl::vector0<mpl_::na>, 0>, boost::multi_index::detail::ordered_non_unique_tag>::iterator {aka boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<Placeholder, std::allocator<Placeholder> > > >}')
Followed by the usual long list of candidates due to c++ template options.