
On 2/4/2011 12:02 PM, Dave Abrahams wrote:
On Thu, Feb 3, 2011 at 6:02 PM, Steven Watanabe<watanabesj@gmail.com> wrote:
n 2/3/2011 2:42 PM, Edward Diener wrote:
Compiling this code with gcc:
#include<boost/config.hpp> #include<boost/mpl/apply.hpp>
template < class MF, class T
struct myMF : boost::mpl::apply<MF,T> { BOOST_STATIC_CONSTANT(bool,value=type::value); };
int main() { return 0; }
Gives:
"gcc.compile.c++
..\..\..\bin.v2\libs\tti\test\TestMFHasTypeMFC.test\gcc-mingw-4.5.2\debug\TestMFHasTypeMFC.o
TestMFHasTypeMFC.cpp:18:5: error: 'type' has not been declared
gcc is correct. Members of a dependent base class are not visible in the derived class. (This is necessary to allow the template to be parsed before the template arguments are known.).
Add using typename boost::mpl::apply<MF,T>::type;
This is easier, neh?
struct myMF : boost::mpl::apply<MF,T> { BOOST_STATIC_CONSTANT(bool,value=myMF::type::value); };
On the other hand, if this thing is returning an MPL integral constant, why wouldn't you simply:
struct myMF : boost::mpl::apply<MF,T>::type {};
and be done with it?
The last suggestion works well, as does the first. But I have some confusion about boost::mpl::apply which neither your MPL book nor the Boost docs clears up for me. As I understand it 'apply' invokes the 'apply' metafunction in a metafunction class and apply<...>::type returns the invoked metafunction's type. If I am deriving from the metafunction's type, then 'myMF' itself does not have a 'type' but only a 'value'. Is this correct or do I have a basic misunderstanding of how boost::mpl::apply works ?