member hook implementation for splay_multiset in Boost::Intrusive

285 views Asked by At

I was implementing boost::intrusive for one of my project on visual C++ 2008 and i stumbled upon a problem. i am using splay hooks for splay_multiset containers. I have defined splay hook publically under MyClass (code below).

#include <boost/intrusive/unordered_set.hpp>
#include <boost/intrusive/splay_set.hpp>
#include <iostream>

using namespace boost::intrusive;

class MyClass 
{              
   int int_;

   public:

   MyClass(int i)
      :  int_(i)
   {}

   splay_set_member_hook<link_mode<normal_link> > memberSplayHook;

//**OPTION-1**
//PROBLEM CODE SEGMENT ++
//typedef member_hook<MyClass, splay_set_member_hook<link_mode<normal_link> >, &MyClass::memberSplayHook> MemberOption;       
//typedef splay_multiset<MyClass, MemberOption> MemberMultiSet; 
//PROBLEM CODE SEGMENT --

    MemberMultiSet mmset;
};

//**OPTION-2**
//WORKING CODE SEGMENT ++
typedef member_hook<MyClass, splay_set_member_hook<link_mode<normal_link> >, &MyClass::memberSplayHook> MemberOption;       
typedef splay_multiset<MyClass, MemberOption> MemberMultiSet; 
//WORKING CODE SEGMENT --


int main()
{
   return 0;
}

The problem is, to use splay_multiset, whatever option i choose (either option-1 or 2, mention in code), in both cases i see compilation errors.

When Option-1 is enabled (option-2 is commented), i see errors below:

1>d:\projects\sampleproject\sample.cpp(21) : error C2327: 'MyClass::memberSplayHook' : is not a type name, static, or enumerator
1>d:\projects\sampleproject\sample.cpp(21) : error C2065: 'memberSplayHook' : undeclared identifier
1>d:\projects\sampleproject\sample.cpp(22) : error C3203: 'member_hook' : unspecialized class template can't be used as a template argument for template parameter 'O1', expected a real type

While, when Option-2 is enabled (option-1 is commented out), i dont see undeclared identifier error msg as these errors coming with option-1. But i do see errors like below (which are obvious).

1>d:\projects\sampleproject\sample.cpp(25) : error C2146: syntax error : missing ';' before identifier 'mmset'
1>d:\projects\sampleproject\sample.cpp(25) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

My question is why i am getting error in first case? What can i do to get pass this issue?

1

There are 1 answers

1
Christian Stieber On BEST ANSWER

Boost member hooks have (always?) been broken, since they don't compile with Visual C++.

I don't have a VS at hand to check for the precise error message so I might be wrong (but reading 'member hooks' and 'Visual C++' always triggers 'there's a problem'-mode), but do try to check this:

http://permalink.gmane.org/gmane.comp.lib.boost.user/56875

EDIT: Don't take the headline literally -- the same applies to Visual C++ 2010 and 2012. All my member hooks use this workaround; at some point I might even try to understand what it does, or more importantly, how to package it into a more comfortable setup for less "I need to find a previous implementation of this workaround so I can copy-and-modify it"...