[mpl] Strange error using boost::mpl::eval_if

No doubt I have had some sort of C++ brain blockage but the following code using boost::mpl::eval_if gives an error and I cannot see how this would be. This is a simplified case of a more serious problem. --------------------------------------------------------------- #include <boost/mpl/bool.hpp> #include <boost/mpl/eval_if.hpp> template<class T,class C> struct AAA { static const bool value=true; typedef boost::mpl::bool_<value> type; }; template<class T> struct CCC { static const bool value=true; typedef boost::mpl::bool_<value> type; }; template<class T> struct BBB : CCC<T> { }; template<class T1,class T2,class T3,class T4> struct DDD : boost::mpl::eval_if < boost::mpl::false_, BBB<T1>, AAA<int,int> > { }; template < class T1, class T2 = int, class T3 = int, class T4 = int
struct EEE : DDD<T1,T2,T3,T4> { }; int main() { bool result = EEE<int,int>::value; return(result ? 1 : 0); } ----------------------------------------------------------------------- Compiling with gcc 4.6.0 in MingW under Windows I get: test_has_mem_fun.cpp: In function 'int main()': test_has_mem_fun.cpp:50:17: error: 'value' is not a member of 'EEE<int, int>' "g++" -ftemplate-depth-128 -O0 -fno-inline -Wall -pedantic -g -Wno-variadic-macros -std=c++0x -DBOOST_ALL_NO_LIB=1 -I"..\..\.." -c -o "..\..\..\bin.v2\libs\tti\test\test_has_mem_fun.test\gcc-mingw-4.6.0\debug\test_has_mem_fun.o" "test_has_mem_fun.cpp" ----------------------------------------------------------------------- I must be overlooking something obvious but I cannot see it. Any help showing me what is wrong would be appreciated.

AMDG On 11/11/2012 06:13 PM, Edward Diener wrote:
No doubt I have had some sort of C++ brain blockage but the following code using boost::mpl::eval_if gives an error and I cannot see how this would be. This is a simplified case of a more serious problem.
---------------------------------------------------------------
<snip>
template<class T1,class T2,class T3,class T4> struct DDD : boost::mpl::eval_if < boost::mpl::false_, BBB<T1>, AAA<int,int> > { };
<snip>
int main() { bool result = EEE<int,int>::value; return(result ? 1 : 0); }
-----------------------------------------------------------------------
Compiling with gcc 4.6.0 in MingW under Windows I get:
test_has_mem_fun.cpp: In function 'int main()': test_has_mem_fun.cpp:50:17: error: 'value' is not a member of 'EEE<int, int>'
<snip>
-----------------------------------------------------------------------
I must be overlooking something obvious but I cannot see it. Any help showing me what is wrong would be appreciated.
I think you're missing the ::type after eval_if. In Christ, Steven Watanabe

On 11/11/2012 9:21 PM, Steven Watanabe wrote:
AMDG
On 11/11/2012 06:13 PM, Edward Diener wrote:
No doubt I have had some sort of C++ brain blockage but the following code using boost::mpl::eval_if gives an error and I cannot see how this would be. This is a simplified case of a more serious problem.
---------------------------------------------------------------
<snip>
template<class T1,class T2,class T3,class T4> struct DDD : boost::mpl::eval_if < boost::mpl::false_, BBB<T1>, AAA<int,int> > { };
<snip>
int main() { bool result = EEE<int,int>::value; return(result ? 1 : 0); }
-----------------------------------------------------------------------
Compiling with gcc 4.6.0 in MingW under Windows I get:
test_has_mem_fun.cpp: In function 'int main()': test_has_mem_fun.cpp:50:17: error: 'value' is not a member of 'EEE<int, int>'
<snip>
-----------------------------------------------------------------------
I must be overlooking something obvious but I cannot see it. Any help showing me what is wrong would be appreciated.
I think you're missing the ::type after eval_if.
I realized not that I was missing ::type directly after eval_if but after the final expression, which instead of: bool result = EEE<int,int>::value; should be bool result = EEE<int,int>::type::value; Thanks for waking me up about this.

Edward Diener <eldiener <at> tropicsoft.com> writes:
template<class T1,class T2,class T3,class T4> struct DDD : boost::mpl::eval_if < boost::mpl::false_, BBB<T1>, AAA<int,int> > { };
You didn't execute your eval_if with ::type -- Maxim
participants (3)
-
Edward Diener
-
Maxim Yanchenko
-
Steven Watanabe