0

I'm trying to make a boost::multi_index container that uses member functions w/ parameters as keys.

class Data {
public:
   std::string get(const std::string & _attr) { return _internals_fetch_data(_attr); }

/*
   assume some implementation for storing data in some structure(s)
*/
};

Suppose I have a rectangular list of these data items that I want to multiple indicies over. rectangular means all items in list have the same attributes via get()

The boost::multi_index declaration is something like

typedef multi_index_container<
  Data,
  indexed_by<
   ordered_unique<
    BOOST_MULTI_INDEX_CONST_MEM_FUN(Data,String,get)
   >
  >
> my_container;

Except that BOOST_MULTI_INDEX_CONST_MEM_FUNCT() does not have these features. Composite keys still work with member variables.

How do I get around this ? It doesn't look like I can give ordered_unique<> a boost::function1

EDIT:

After some thought, here is the gist of what I'm trying to do.

boost::multi_index determines it's indexing features during compile time. How do I circumvent these features and use run-time determined indexes ?

1 Answer 1

2

What do you suppose to pass as argument to function? What is const std::string & _attr?

Anyway, BOOST_MULTI_INDEX_CONST_MEM_FUN is just a macro for const_mem_fun functor. You could write your own functor const_mem_fun1. But I have no idea how you going to use it. Implementation of const_mem_fun receives object by reference (or wrapper, e.g. shared_ptr) and then it calls member function with no arguments.

boost::multi_index::indexed_by expects type, not an object, as well as ordered_unique expects type. That's why you cannot write const_mem_fun1<Data, std::string, &Data::get>("string"). Why do you cannot use function get with no parameters and create special string field in Data struct?

struct Data {
  std::string _attr;
public:
  std::string get() const { return _internals_fetch_data(_attr); }
};
Sign up to request clarification or add additional context in comments.

3 Comments

That's the problem. Doesn't look like I can use a const_mem_fun1 here.
How are you suppose to pass argument? Something like ordered_unique< const_mem_fun1<Data, std::string, &Data::get>( "string" ) > ?
Maybe ( "string" ) can be a struct/wrapper as another parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.