Boost logo

Boost Users :

From: Scott Meyers (usenet_at_[hidden])
Date: 2006-03-08 16:21:45


Consider this (working) code using Boost.FileSystem:

   fs::directory_iterator di(dir);
   fs::directory_iterator end;
   while (di != end) {
     if (is_directory(*di)) cout << "D\n";
     else cout << "~D\n";
     ++di;
   }

This looks like it should be lambda-able. Here's my attempt:

   for_each(fs::directory_iterator(dir), fs::directory_iterator(),
            if_then_else(bind(&fs::is_directory, _1),
                         cout << "D\n",
                         cout << "~D\n"));

VC7.1 doesn't like this -- the diagnostics are below. Any idea how I can make
this work?

Thanks,

Scott

fs.cpp(39) : error C2784: 'const
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::ifthenelse_action,boost::tuples:
:tuple<boost::lambda::lambda_functor<Arg1>,boost::lambda::lambda_functor<Arg2>,boost::lambda::lambda_functor<Arg3>>>>
boost::lambda::if_then_else
(const boost::lambda::lambda_functor<Arg1> &,const
boost::lambda::lambda_functor<Arg2> &,const boost::lambda::lambda_functor<Arg3>
&)' : could no
t deduce template argument for 'const boost::lambda::lambda_functor<T2> &' from
'std::basic_ostream<_Elem,_Traits>'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         D:\C++\Boost\Current\boost\lambda\if.hpp(100) : see declaration of
'boost::lambda::if_then_else'
fs.cpp(39) : error C2784: 'const
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::ifthenelse_action,boost::tuples:
:tuple<boost::lambda::lambda_functor<Arg1>,boost::lambda::lambda_functor<Arg2>,boost::lambda::lambda_functor<Arg3>>>>
boost::lambda::if_then_else
(const boost::lambda::lambda_functor<Arg1> &,const
boost::lambda::lambda_functor<Arg2> &,const boost::lambda::lambda_functor<Arg3>
&)' : could no
t deduce template argument for 'const boost::lambda::lambda_functor<T2> &' from
'std::basic_ostream<_Elem,_Traits>'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         D:\C++\Boost\Current\boost\lambda\if.hpp(100) : see declaration of
'boost::lambda::if_then_else'
fs.cpp(39) : error C2784: 'const
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::ifthenelse_action,boost::tuples:
:tuple<boost::lambda::lambda_functor<Arg1>,boost::lambda::lambda_functor<Arg2>,boost::lambda::lambda_functor<Arg3>>>>
boost::lambda::if_then_else
(const boost::lambda::lambda_functor<Arg1> &,const
boost::lambda::lambda_functor<Arg2> &,const boost::lambda::lambda_functor<Arg3>
&)' : could no
t deduce template argument for 'const boost::lambda::lambda_functor<T2> &' from
'std::basic_ostream<_Elem,_Traits>'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         D:\C++\Boost\Current\boost\lambda\if.hpp(100) : see declaration of
'boost::lambda::if_then_else'
fs.cpp(39) : error C2784: 'const
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::ifthenelse_action,boost::tuples:
:tuple<boost::lambda::lambda_functor<Arg1>,boost::lambda::lambda_functor<Arg2>,boost::lambda::lambda_functor<Arg3>>>>
boost::lambda::if_then_else
(const boost::lambda::lambda_functor<Arg1> &,const
boost::lambda::lambda_functor<Arg2> &,const boost::lambda::lambda_functor<Arg3>
&)' : could no
t deduce template argument for 'const boost::lambda::lambda_functor<T2> &' from
'std::basic_ostream<_Elem,_Traits>'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         D:\C++\Boost\Current\boost\lambda\if.hpp(100) : see declaration of
'boost::lambda::if_then_else'


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net