
Hi, I need help to get started with boost, Im trying about some time to get a little project mine converted to use boost libs. My current project uses raw pointers and std::map. But I want to use shared_ptr and multi_index_container. I cant find help anywhere to my problems with this code, I hope I can get some here. Project Outline: - Strict OO design. - Filesystem emulation (a simple fake filesystem...) - I have one Filesytem interface with one implementation. - I have one Entry interface with three implementations. - Directory is a Entry. - File is a Entry. - Empty is a Entry. See the sample here: http://rafb.net/paste/results/hfHOx934.html , I have done this little sample to start understunding multi_index_container with classes using methods (mem_fun) as "selectors?". What is wrong with it? Please, I really need help to start with boost. But I doesnt want to let use best practices like good design and patterns. Thanks -- Animal Frontline Liberation

----- Mensaje original -----
De: fungos
Hi, I need help to get started with boost, Im trying about some time to get a little project mine converted to use boost libs. My current project uses raw pointers and std::map. But I want to use shared_ptr and multi_index_container. [...] See the sample here: http://rafb.net/paste/results/hfHOx934.html , I have done this little sample to start understunding multi_index_container with classes using methods (mem_fun) as "selectors?". What is wrong with it?
Hello, I can only give a cursory look to your code right now (hope to have more stable Internet access in a couple of days), but looks to me the problem with it is that the memfuns you're using for key selection must be const, i.e. int getSize() const { return size; } etc. HTH, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

Well, I still having trouble to get mem_fun working. multi_index accept
boost mem_fn?
Joaquin, the const still wont work. I stripped down the sample to this code:
[code]
#include
EntryCollection;
void main() {
EntryCollection entries;
Entry a(3);
entries.insert(a); // line 33
}
[/code]
With getSize() const; I get this error:
main.cpp:23: error: could not convert template argument `&Entry::getSize' to
`int (Entry::*)()'
main.cpp:24: error: template argument 1 is invalid
main.cpp:25: error: template argument 1 is invalid
main.cpp:25: error: template argument 2 is invalid
main.cpp:25: error: ISO C++ forbids declaration of `EntryCollection' with no
type
main.cpp: In function `int main(int, char**)':
main.cpp:33: error: `insert' has not been declared
main.cpp:33: error: request for member of non-aggregate type before '('
token
make.exe: *** [main.o] Error 1
On 12/7/06, "JOAQUIN LOPEZ MU?Z"
----- Mensaje original ----- De: fungos
Fecha: Viernes, Diciembre 8, 2006 1:02 am Asunto: [Boost-users] Newbie to boost Para: boost-users@lists.boost.org Hi, I need help to get started with boost, Im trying about some time to get a little project mine converted to use boost libs. My current project uses raw pointers and std::map. But I want to use shared_ptr and multi_index_container. [...] See the sample here: http://rafb.net/paste/results/hfHOx934.html , I have done this little sample to start understunding multi_index_container with classes using methods (mem_fun) as "selectors?". What is wrong with it?
Hello,
I can only give a cursory look to your code right now (hope to have more stable Internet access in a couple of days), but looks to me the problem with it is that the memfuns you're using for key selection must be const, i.e.
int getSize() const { return size; } etc.
HTH,
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Animal Frontline Liberation

"fungos"
EntryCollection;
void main() { EntryCollection entries; Entry a(3); entries.insert(a); // line 33 } Jeff Flinn

Nice! const_mem_fun worked in this sample. I will try to port my map to
multi_index now and see how it performs.
But, I dont want to give up without understund why mem_fun doesnt work.
Anybody has any theory? :D
Thanks Jeff.
On 12/8/06, Jeff F
"fungos"
wrote in message news:e763e59d0612080512k4f02b88cnee2732030a95a5ff@mail.gmail.com... Well, I still having trouble to get mem_fun working. multi_index accept boost mem_fn? Joaquin, the const still wont work. I stripped down the sample to this code: [code]
#include
#include #include using boost::multi_index_container; using namespace ::boost::multi_index;
class Entry { private: int size; public: Entry(int s) : size(s) {} int getSize() const { return size; } };
typedef multi_index_container< Entry, indexed_by< ordered_non_unique
// line 23 Doesn't this work?
ordered_non_unique< const_mem_fun
> > EntryCollection;
void main() { EntryCollection entries; Entry a(3); entries.insert(a); // line 33 }
Jeff Flinn
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Animal Frontline Liberation

fungos wrote:
Nice! const_mem_fun worked in this sample. I will try to port my map to multi_index now and see how it performs. But, I dont want to give up without understund why mem_fun doesnt work. Anybody has any theory? :D
IIRC, you are only allowed access to the const interface of items held by multi_index containers. Non-const methods by definition mutate the object upon which they act, which could change the item's state upon which the sort order is based. That is why you must use multi_index's update functions to modify the state of any of it's items. Jeff Flinn

Ok, so If I want to use a multi_index to manage a large collection of
dynamic data, I need to be constantly updating it using the container update
functions. So I need find a way to my objects known their containers so I
can manage that Update inside the setters of my object. This will work? (I
will try as I get at home again)
On 12/8/06, Jeff F
fungos wrote:
Nice! const_mem_fun worked in this sample. I will try to port my map to multi_index now and see how it performs. But, I dont want to give up without understund why mem_fun doesnt work. Anybody has any theory? :D
IIRC, you are only allowed access to the const interface of items held by multi_index containers. Non-const methods by definition mutate the object upon which they act, which could change the item's state upon which the sort order is based. That is why you must use multi_index's update functions to modify the state of any of it's items.
Jeff Flinn
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Animal Frontline Liberation
participants (3)
-
"JOAQUIN LOPEZ MU?Z"
-
fungos
-
Jeff F