pointer to member function of multi_index

Hi, I am sure this is due to some trivial mistake; the statement to create a pointer member function insert of multi_index container fails in the following code: typedef multi_index_container< std::pair<int,int>, indexed_by< ordered_unique<member<pair<int,int>, int, &pair<int, int>::first> > > > mic; std::pair<mic_index::iterator, bool> (mic_index::*fn)(pair<int,int>) = &mic_index::insert; //compile error The error is due to mismatch in signature as given in the error: std::pair<boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<std::pair<int, int>, ... std::pair<boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<typename SuperMeta::type::node_type> >, bool>... If need be I can post full error message. Appreciate any suggestions. Thanks sandeep

AMDG Sandeep Gupta wrote:
I am sure this is due to some trivial mistake; the statement to create a pointer member function insert of multi_index container fails in the following code:
typedef multi_index_container< std::pair<int,int>, indexed_by< ordered_unique<member<pair<int,int>, int, &pair<int, int>::first> > > > mic;
std::pair<mic_index::iterator, bool> (mic_index::*fn)(pair<int,int>) = &mic_index::insert; //compile error
The error is due to mismatch in signature as given in the error: std::pair<boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<std::pair<int, int>, ... std::pair<boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<typename SuperMeta::type::node_type> >, bool>...
If need be I can post full error message. Appreciate any suggestions.
The signature is std::pair<mic_index::iterator, bool> (mic_index::*fn)(const pair<int,int>&); However, it is not usually a good idea to rely on the exact signature of library member functions. For instance, the standard library allows member functions to have extra default arguments. In the case of multi_index, using a reference to const will not always work because multi_index uses call_traits. In Christ, Steven Watanabe

On Tue, Mar 17, 2009 at 7:57 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Sandeep Gupta wrote:
I am sure this is due to some trivial mistake; the statement to create a pointer member function insert of multi_index container fails in the following code:
typedef multi_index_container< std::pair<int,int>, indexed_by< ordered_unique<member<pair<int,int>, int, &pair<int, int>::first> > > > mic;
std::pair<mic_index::iterator, bool> (mic_index::*fn)(pair<int,int>) = &mic_index::insert; //compile error
The error is due to mismatch in signature as given in the error:
std::pair<boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<std::pair<int, int>, ...
std::pair<boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<typename SuperMeta::type::node_type> >, bool>...
If need be I can post full error message. Appreciate any suggestions.
The signature is std::pair<mic_index::iterator, bool> (mic_index::*fn)(const pair<int,int>&);
However, it is not usually a good idea to rely on the exact signature of library member functions. For instance, the standard library allows member functions to have extra default arguments. In the case of multi_index, using a reference to const will not always work because multi_index uses call_traits.
In Christ, Steven Watanabe
I see. So I take it that its best to avoid creating function objects or pointer to standard library member functions. Thanks sandeep

AMDG Sandeep Gupta wrote:
On Tue, Mar 17, 2009 at 7:57 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
However, it is not usually a good idea to rely on the exact signature of library member functions. For instance, the standard library allows member functions to have extra default arguments. In the case of multi_index, using a reference to const will not always work because multi_index uses call_traits I see. So I take it that its best to avoid creating function objects or pointer to standard library member functions.
It's okay to create a function objects like those in phoenix http://www.boost.org/libs/spirit/phoenix/doc/html/phoenix/container.html as long as you don't bind a member pointer in the process. In Christ, Steven Watanabe

On Tue, Mar 17, 2009 at 8:40 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Sandeep Gupta wrote:
On Tue, Mar 17, 2009 at 7:57 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
However, it is not usually a good idea to rely on the exact signature of library member functions. For instance, the standard library allows member functions to have extra default arguments. In the case of multi_index, using a reference to const will not always work because multi_index uses call_traits
I see. So I take it that its best to avoid creating function objects or pointer to standard library member functions.
It's okay to create a function objects like those in phoenix http://www.boost.org/libs/spirit/phoenix/doc/html/phoenix/container.html as long as you don't bind a member pointer in the process.
Hi Steve, Would trouble you for one more clarification regarding this issue. How do we go about binding overloaded member functions without specifying exact signature. From what I could gather to adapt overloaded functions we need the full signature. Thanks sandeep

AMDG Sandeep Gupta wrote:
On Tue, Mar 17, 2009 at 8:40 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
It's okay to create a function objects like those in phoenix http://www.boost.org/libs/spirit/phoenix/doc/html/phoenix/container.html as long as you don't bind a member pointer in the process.
Would trouble you for one more clarification regarding this issue. How do we go about binding overloaded member functions without specifying exact signature. From what I could gather to adapt overloaded functions we need the full signature.
You have to use a forwarding function object like those I referred to above. In Christ, Steven Watanabe

On Wed, Mar 18, 2009 at 12:04 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Sandeep Gupta wrote:
On Tue, Mar 17, 2009 at 8:40 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
It's okay to create a function objects like those in phoenix http://www.boost.org/libs/spirit/phoenix/doc/html/phoenix/container.html as long as you don't bind a member pointer in the process.
Would trouble you for one more clarification regarding this issue. How do we go about binding overloaded member functions without specifying exact signature. From what I could gather to adapt overloaded functions we need the full signature.
You have to use a forwarding function object like those I referred to above.
On first glance I missed how to go about using them. I am afraid this approach fails as well. The commands: vector<int> myvec; bind(push_back, myvec, arg1)(5); give error: PhoneixTricks.cpp:29: instantiated from here /home/sandeep/Computing/boost_1_38_0/boost/spirit/home/phoenix/core/detail/function_eval.hpp:116: error: no class template named ‘result’ in ‘struct boost::phoenix::function<boost::phoenix::stl::push_back>’ /home/sandeep/Computing/boost_1_38_0/boost/spirit/home/phoenix/core/detail/function_eval.hpp:126: error: no class template named ‘result’ in ‘struct boost::phoenix::function<boost::phoenix::stl::push_back>’ PhoneixTricks.cpp: In function ‘int main()’: A somewhat related problem appeared here http://www.nabble.com/-Spirit2--Phoenix-2-binding-function-objects-td2185312.... Again thanks so much more so for being patient. -Sandeep

AMDG Sandeep Gupta wrote:
On first glance I missed how to go about using them. I am afraid this approach fails as well. The commands: vector<int> myvec; bind(push_back, myvec, arg1)(5);
error: no class template named ‘result’ in ‘struct boost::phoenix::function<boost::phoenix::stl::push_back>’
Again thanks so much more so for being patient.
phoenix::function doesn't need bind: phoenix::push_back(phoenix::ref(myvec), arg1)(5); In Christ, Steven Watanabe

On Wed, Mar 18, 2009 at 3:18 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Sandeep Gupta wrote:
On first glance I missed how to go about using them. I am afraid this approach fails as well. The commands: vector<int> myvec; bind(push_back, myvec, arg1)(5);
error: no class template named ‘result’ in ‘struct boost::phoenix::function<boost::phoenix::stl::push_back>’
Again thanks so much more so for being patient.
phoenix::function doesn't need bind:
phoenix::push_back(phoenix::ref(myvec), arg1)(5);
Thanks Steven,. Unfortunately, this also fails. Below is the error. error: PhoneixTricks.cpp: In function ‘int main()’: PhoneixTricks.cpp:30: error: no match for call to ‘(boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::detail::function_eval<2>, boost::fusion::vector<boost::phoenix::value<boost::phoenix::stl::push_back>, boost::phoenix::value<boost::reference_wrapper<std::vector<int, std::allocator<int> > > >, boost::phoenix::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >) (int)’ /home/sandeep/Computing/boost_1_38_0/boost/spirit/home/phoenix/core/actor.hpp:91: note: candidates are: typename boost::mpl::eval_if<typename Eval::no_nullary, boost::mpl::identity<boost::phoenix::detail::error_expecting_arguments>, boost::phoenix::eval_result<Eval, boost::phoenix::basic_environment<boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> >
::type boost::phoenix::actor<Eval>::operator()() const [with Eval = boost::phoenix::composite<boost::phoenix::detail::function_eval<2>, boost::fusion::vector<boost::phoenix::value<boost::phoenix::stl::push_back>, boost::phoenix::value<boost::reference_wrapper<std::vector<int, std::allocator<int> > > >, boost::phoenix::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> >] /home/sandeep/Computing/boost_1_38_0/boost/spirit/home/phoenix/core/actor.hpp:108: note: typename boost::phoenix::actor<Eval>::result<boost::phoenix::actor<Eval> ()(T0&)>::type boost::phoenix::actor<Eval>::operator()(T0&) const [with T0 = int, Eval = boost::phoenix::composite<boost::phoenix::detail::function_eval<2>, boost::fusion::vector<boost::phoenix::value<boost::phoenix::stl::push_back>, boost::phoenix::value<boost::reference_wrapper<std::vector<int, std::allocator<int> > > >, boost::phoenix::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> >]

AMDG Sandeep Gupta wrote:
On Wed, Mar 18, 2009 at 3:18 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
phoenix::function doesn't need bind:
phoenix::push_back(phoenix::ref(myvec), arg1)(5);
Thanks Steven,. Unfortunately, this also fails. Below is the error.
Whoops. The function object generated by phoenix doesn't take rvalues. int x = 5; phoenix::push_back(phoenix::ref(myvec), arg1)(x); In Christ, Steven Watanabe

On Wed, Mar 18, 2009 at 5:47 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Sandeep Gupta wrote:
On Wed, Mar 18, 2009 at 3:18 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
phoenix::function doesn't need bind:
phoenix::push_back(phoenix::ref(myvec), arg1)(5);
Thanks Steven,. Unfortunately, this also fails. Below is the error.
Whoops. The function object generated by phoenix doesn't take rvalues.
int x = 5; phoenix::push_back(phoenix::ref(myvec), arg1)(x);
Works perfectly now. As always, I really appreciate all your help and taking trouble to look over even the trivial mistakes. thanks sandeep

Sandeep Gupta wrote:
Hi, I am sure this is due to some trivial mistake; the statement to create a pointer member function insert of multi_index container fails in the following code:
typedef multi_index_container< std::pair<int,int>, indexed_by< ordered_unique<member<pair<int,int>, int, &pair<int, int>::first> > > > mic;
std::pair<mic_index::iterator, bool> (mic_index::*fn)(pair<int,int>) = &mic_index::insert; //compile error
Are you sure the pair is taken by value?

On Wed, Mar 18, 2009 at 4:19 AM, Mathias Gaunard <mathias.gaunard@ens-lyon.org> wrote:
Sandeep Gupta wrote:
Hi, I am sure this is due to some trivial mistake; the statement to create a pointer member function insert of multi_index container fails in the following code:
typedef multi_index_container< std::pair<int,int>, indexed_by< ordered_unique<member<pair<int,int>, int, &pair<int, int>::first> > > > mic;
std::pair<mic_index::iterator, bool> (mic_index::*fn)(pair<int,int>) = &mic_index::insert; //compile error
Are you sure the pair is taken by value?
Hi Gaunard, Yes. In real code i am indexing graph vertex which can be exists as several copies. thanks sandeep
participants (3)
-
Mathias Gaunard
-
Sandeep Gupta
-
Steven Watanabe