Insertion/Use of boost::multi_index
Hi All ,
I have created a boost::multi_index container for my use and it compiles
successfully. I would like to add my pointer objects to it.
boost::multi_index does not seem to have an insert method defined which
just takes one arguement which is what I would like the container to store.
Maybe I didnt understand how boost::multi_index is meant to be used. Can
you please explain to me how to insert an object which I wish the store in
the container defined? How is it intended to be used? The container I
defined is ,
typedef boost::multi_index_ClassX<
ClassX*,
boost::multi_index::indexed_by<
boost::multi_index::hashed_unique<
boost::multi_index::const_mem_fun
MultiIndexedClassX;
I would like to do an equivalent of, MultiIndexedClassX sample; ClassX a; sample.insert(&a); <- Since I am interested in storing a *X and I would like it to be indexed by various parameters of X. Also please let me know how to, 1. Insert *X into the container 2. Look up by a) Value of ParentOfClassX::Key1 b) Value of ParentOfClassX::Key2 Please also let me know if I have some basic understanding wrong since I am getting confused a lot in trying to use boost::multi_index. Thanks in advance, Ram
Hi,
To add,
Hi,
To add,
When I insert like "sample.insert(&a);", I get errors like,
.
.
.
kytj.cpp
ky_op_tj.cpp
c:\code\common\lib\boost\boost\multi_index\hashed_index.hpp(1155) : error
C2064: term does not evaluate to a function taking 2 arguments
class does not define an 'operator()' or a user defined conversion
operator to a pointer-to-function or reference-to-function that takes
appropriate number of arguments
c:\code\common\lib\\boost\boost\multi_index\hashed_index.hpp(1152)
: while compiling class template member function 'bool
boost::multi_index::detail::hashed_index
El 19/09/2016 a las 7:54, Ram escribió:
Hi All ,
I have created a boost::multi_index container for my use and it compiles successfully. [...] The container I defined is ,
typedef boost::multi_index_ClassX< ClassX*, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< boost::multi_index::const_mem_fun
, boost::multi_index::const_mem_fun , MultiIndexedClassX;
I'm afraid this is seriously wrong (leaving aside the translation typos such as "boost::multi_index_ClassX" instead of "boost::multi_index_container" etc.) The structure of a definition of a multi_index_container is multi_index_container< element_type, indexed_by< index_specifier1<index1 args>, index_specifier2<index2 args>, ... >
where each index_specifier is one of "hashed_unique", "hashed_non_unique",
"ordered_unique", etc. I assume your intention is to have *two* hashed
indices
(by key1 and key2, respectively), so rather than
indexed_by<
hashed_unique
(which is what you've written), the definition has to follow this structure:
indexed_by<
hashed_unique
See the difference? Your original definition is just plain wrong, and the fact that it seems to compile is sheer luck (or lack of it): once you start trying to use it, compile-time errors will pop up. (if you're curious, Boost.MultiIndex is trying to use your second const_mem_fun as a hash function of the first const_mem_fun, which, of course, makes no sense, but this is what you instructed the lib to do). I've written a small test program reproducing your scenario that you can play with at http://coliru.stacked-crooked.com/a/456f8546e51a29e6 Note that, here, sample.insert(&a) works without problems. Joaquín M López Muñoz
Hi Joaquin,
This is the exact error I am facing,
When I insert like "sample.insert(&a);", I get errors like,
.
.
.
kytj.cpp
ky_op_tj.cpp
c:\code\common\lib\boost\boost\multi_index\hashed_index.hpp(1155) : error
C2064: term does not evaluate to a function taking 2 arguments
class does not define an 'operator()' or a user defined conversion
operator to a pointer-to-function or reference-to-function that takes
appropriate number of arguments
c:\code\common\lib\\boost\boost\multi_index\hashed_index.hpp(1152)
: while compiling class template member function 'bool
boost::multi_index::detail::hashed_index
El 19/09/2016 a las 7:54, Ram escribió:
Hi All ,
I have created a boost::multi_index container for my use and it compiles successfully. [...] The container I defined is ,
typedef boost::multi_index_ClassX< ClassX*, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< boost::multi_index::const_mem_fun
, boost::multi_index::const_mem_fun , MultiIndexedClassX;
I'm afraid this is seriously wrong (leaving aside the translation typos such as "boost::multi_index_ClassX" instead of "boost::multi_index_container" etc.) The structure of a definition of a multi_index_container is
multi_index_container< element_type, indexed_by< index_specifier1<index1 args>, index_specifier2<index2 args>, ... >
where each index_specifier is one of "hashed_unique", "hashed_non_unique", "ordered_unique", etc. I assume your intention is to have *two* hashed indices (by key1 and key2, respectively), so rather than
indexed_by< hashed_unique
(which is what you've written), the definition has to follow this structure:
indexed_by< hashed_unique
, hashed_unique See the difference? Your original definition is just plain wrong, and the fact that it seems to compile is sheer luck (or lack of it): once you start trying to use it, compile-time errors will pop up. (if you're curious, Boost.MultiIndex is trying to use your second const_mem_fun as a hash function of the first const_mem_fun, which, of course, makes no sense, but this is what you instructed the lib to do).
I've written a small test program reproducing your scenario that you can play with at
http://coliru.stacked-crooked.com/a/456f8546e51a29e6
Note that, here, sample.insert(&a) works without problems.
Joaquín M López Muñoz
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
El 19/09/2016 a las 9:32, Ram escribió:
Hi Joaquin,
This is the exact error I am facing, [...]
Please don't top post, see http://www.boost.org/community/policy.html#quoting Please review my previous answer, apply the necessary changes and see if your error on insertion persists (which I hope will not). Joaquín M López Muñoz
Oops, I am wrong. I will try the suggestion you just gave, and the right way to write it and will try it out and let you know. Also please let me know how to extract value using specific keys. One more question, "Please don't top post, see http://www.boost.org/community /policy.html#quoting" I am not sure I understood that, please let me know what that means. Will go out for lunch now and come back and try it and let you know. Thanks a lot! -Ram On Mon, Sep 19, 2016 at 1:07 PM, Joaquin M López Muñoz < joaquinlopezmunoz@gmail.com> wrote:
El 19/09/2016 a las 9:32, Ram escribió:
Hi Joaquin,
This is the exact error I am facing, [...]
Please don't top post, see http://www.boost.org/community /policy.html#quoting
Please review my previous answer, apply the necessary changes and see if your error on insertion persists (which I hope will not).
Joaquín M López Muñoz _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
El 19/09/2016 a las 9:46, Ram escribió:
[...]
One more question, "Please don't top post, see http://www.boost.org/community/policy.html#quoting http://www.boost.org/community/policy.html#quoting" I am not sure I understood that, please let me know what that means.
See https://en.wikipedia.org/wiki/Posting_style#Top-posting . Nettiquete in Boost requires that you not top post your replies leaving the previous post untouched at the bottom (as you're doing) but rather answer in line with the previous post and trim any unnecessary prior context (as I'm doing). Joaquín M López Muñoz
Sorry Joaquin, will do that from next time..
Corrected my code to,
typedef boost::multi_index_container<
ClassX*, //mapped value
boost::multi_index::indexed_by
, boost::multi_index::hashed_unique< boost::multi_index::const_mem_fun
//hashed index by unique key1 , boost::multi_index::hashed_unique< boost::multi_index::const_mem_fun //hashed index by unique key3/ID ClassXMultiKeyIndexed;
ClassXMultiKeyIndexed sample;
and tried compiling and I still get this while compiling(there are more
errors below, but removed them),
.
.
.
kytj.cpp
ky_op_tj.cpp
c:\code\lib\boost\boost\multi_index\detail\node_type.hpp(43) : error C2825:
'boost::multi_index::detail::index_node_applier::apply<
IndexSpecifierIterator,Super>::index_specifier': must be a class or
namespace when followed by '::'
with
[
IndexSpecifierIterator=boost::mpl::v_iter
Sorry,
This was the error,
.
.
kytj.cpp
ky_op_tj.cpp
c:\code\common\lib\boost\boost\detail\allocator_utilities.hpp(153) : error
C2061: syntax error : identifier 'p'
c:\code\common\lib\boost\boost\multi_index\detail\index_base.hpp(105) : see
reference to function template instantiation 'void
boost::detail::allocator::construct
El 19/09/2016 a las 10:59, Ram escribió:
Sorry Joaquin, will do that from next time..
OK, when you do it I'll be happy to address your questions. In the meantime please understand it is not convenient for me or the community to follow up on an unproperly formatted thread like this. Joaquín M López Muñoz
Hi Joaquin, Will start a new thread with the name : "Insertion/Use of boost::multi_index - new thread" Let this thread end here. Thanks and sorry, Ram
participants (2)
-
Joaquin M López Muñoz
-
Ram