Boost logo

Boost Users :

From: Hossein Haeri (powerprogman_at_[hidden])
Date: 2006-05-06 09:18:51


Hi Steve.

> I get it (on VC++2003) as the problem being a lack
> of return_type typedefs.

Doesn't work for GCC 3.3.1 either! :( BTW, I have
modified the files, and added your code as well. I see
due to your additions the resulting errors have been
changed. In case you are nice enough to take another
look, see the PS please. :)

Many thanks for the time you took so far! :)

TTFN,
--Hossein

//Print.hpp
#include <iterator>
#include <iosfwd>
#include <algorithm>

template <class Container, size_t i>
struct PrintAux
{
  typedef std::ostream& return_type;

  std::ostream& operator () (const Container& c,
std::ostream& out) const
  {
    if(out)
    {
      PrintAux<typename Container::value_type, i - 1>
newPrint;
      /*
      for(typename Container::const_iterator j =
c.begin(); j != c.end(); ++j)
        newPrint(*j, out);
// */
      for_each(c.begin(), c.end(), bind(newPrint, _2,
out));
    }
    return out;
  }
};

template <class Container>
struct PrintAux<Container, 1>
{
  typedef std::ostream& return_type;

  std::ostream& operator () (const Container& c,
std::ostream& out) const
  {
    if(out)
      std::copy(c.begin(),
                c.end(),
                std::ostream_iterator<typename
Container::value_type>(out, " "));
    return out;
  }
};

template <class Container>
struct PrintAux<Container, 0>
{
  class
ERROR_PRINT_NOT_FOR_SCALER_VARIABLES_ONLY_FOR_CONTAIERS;
 
ERROR_PRINT_NOT_FOR_SCALER_VARIABLES_ONLY_FOR_CONTAIERS
e;
};

template <typename>
struct ContainerDepth
{
  enum {value = 0};
};

template <template <typename> class Container,
typename T>
struct ContainerDepth<Container<T> >
{
  enum {value = ContainerDepth<typename
Container<T>::value_type>::value + 1};
};

template <typename T>
std::ostream& Print(const T& t, std::ostream& out)
{
  return PrintAux<T, ContainerDepth<T>::value> () (t,
out);
}

//Print.cpp
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>

#include <boost/bind.hpp>

#include "Print.hpp"

using std::cin;
using std::cout;
using std::endl;
using std::copy;
using std::vector;
using std::transform;
using std::multiplies;
using std::plus;

using boost::bind;

int main()
{
  int a1[] = {1, 2, 3, 4};
  const size_t n(sizeof(a1)/sizeof(*a1));
  int a2[n] = {5, 6, 7, 8};
  
  vector<int> v(a1, a1 + n);
  vector<vector<int> > m(1, v);
  m.push_back(vector<int>(a2, a2 + n));
  Print(m, cout);

  cin.get();
  return 0;
}

Error Message:

Compiler: Default compiler
Building Makefile: "E:\My Documents\My
Programmes\Tests\Aarash\Makefile.win"
Executing make...
make.exe -f "E:\My Documents\My
Programmes\Tests\Aarash\Makefile.win" all
g++.exe -c Print.cpp -o Print.o -I"E:/Program
Files/Dev-Cpp/include/c++/3.3.1" -I"E:/Program
Files/Dev-Cpp/include/c++/3.3.1/mingw32"
-I"E:/Program
Files/Dev-Cpp/include/c++/3.3.1/backward"
-I"E:/Program
Files/Dev-Cpp/lib/gcc-lib/mingw32/3.3.1/include"
-I"E:/Program Files/Dev-Cpp/include"

E:/Program
Files/Dev-Cpp/include/c++/3.3.1/bits/ios_base.h: In
copy constructor
   `std::basic_ios<char, std::char_traits<char>
>::basic_ios(const
   std::basic_ios<char, std::char_traits<char> >&)':
Print.hpp:19: instantiated from `std::ostream&
PrintAux<Container, i>::operator()(const Container&,
std::ostream&) const [with Container =
std::vector<std::vector<int, std::allocator<int> >,
std::allocator<std::vector<int, std::allocator<int> >
> >, unsigned int i = 2]'
Print.hpp:62: instantiated from `std::ostream&
Print(const T&, std::ostream&) [with T =
std::vector<std::vector<int, std::allocator<int> >,
std::allocator<std::vector<int, std::allocator<int> >
> >]'
Print.cpp:30: instantiated from here
E:/Program
Files/Dev-Cpp/include/c++/3.3.1/bits/ios_base.h:668:
error: `
   std::ios_base::ios_base(const std::ios_base&)' is
private
Print.hpp:19: error: within this context

Print.hpp: In member function `std::ostream&
PrintAux<Container,
   i>::operator()(const Container&, std::ostream&)
const [with Container =

   std::vector<std::vector<int, std::allocator<int> >,

   std::allocator<std::vector<int, std::allocator<int>
> > >, unsigned int i =
   2]':
Print.hpp:62: instantiated from `std::ostream&
Print(const T&, std::ostream&) [with T =
std::vector<std::vector<int, std::allocator<int> >,
std::allocator<std::vector<int, std::allocator<int> >
> >]'
Print.cpp:30: instantiated from here
Print.hpp:19: error: initializing argument 3 of `
   boost::_bi::bind_t<boost::_bi::unspecified, F,
typename
   boost::_bi::list_av_2<A1, A2>::type> boost::bind(F,
A1, A2) [with F =
   PrintAux<std::vector<int, std::allocator<int> >,
1>, A1 = boost::arg<2>, A2
   = std::basic_ostream<char, std::char_traits<char>
>]'
E:/Program Files/Dev-Cpp/include/boost/bind.hpp: At
global scope:
E:/Program Files/Dev-Cpp/include/boost/bind.hpp: In
instantiation of
`boost::_bi::result_traits<boost::_bi::unspecified,
PrintAux<std::vector<int, std::allocator<int> >, 1>
>':
E:/Program
Files/Dev-Cpp/include/boost/bind/bind_template.hpp:15:
  instantiated from
`boost::_bi::bind_t<boost::_bi::unspecified,
PrintAux<std::vector<int, std::allocator<int> >, 1>,
boost::_bi::list2<boost::arg<2>,
boost::_bi::value<std::basic_ostream<char,
std::char_traits<char> > > > >'
Print.hpp:19: instantiated from `std::ostream&
PrintAux<Container, i>::operator()(const Container&,
std::ostream&) const [with Container =
std::vector<std::vector<int, std::allocator<int> >,
std::allocator<std::vector<int, std::allocator<int> >
> >, unsigned int i = 2]'
Print.hpp:62: instantiated from `std::ostream&
Print(const T&, std::ostream&) [with T =
std::vector<std::vector<int, std::allocator<int> >,
std::allocator<std::vector<int, std::allocator<int> >
> >]'
Print.cpp:30: instantiated from here
E:/Program Files/Dev-Cpp/include/boost/bind.hpp:62:
error: no type named `
   result_type' in `struct PrintAux<std::vector<int,
std::allocator<int> >, 1>'

E:/Program
Files/Dev-Cpp/include/boost/bind/bind_template.hpp: In
instantiation of
`boost::_bi::bind_t<boost::_bi::unspecified,
PrintAux<std::vector<int, std::allocator<int> >, 1>,
boost::_bi::list2<boost::arg<2>,
boost::_bi::value<std::basic_ostream<char,
std::char_traits<char> > > > >':
Print.hpp:19: instantiated from `std::ostream&
PrintAux<Container, i>::operator()(const Container&,
std::ostream&) const [with Container =
std::vector<std::vector<int, std::allocator<int> >,
std::allocator<std::vector<int, std::allocator<int> >
> >, unsigned int i = 2]'
Print.hpp:62: instantiated from `std::ostream&
Print(const T&, std::ostream&) [with T =
std::vector<std::vector<int, std::allocator<int> >,
std::allocator<std::vector<int, std::allocator<int> >
> >]'

Print.cpp:30: instantiated from here
E:/Program
Files/Dev-Cpp/include/boost/bind/bind_template.hpp:15:
error: no
   type named `type' in `struct
   boost::_bi::result_traits<boost::_bi::unspecified,
PrintAux<std::vector<int,
   std::allocator<int> >, 1> >'
E:/Program
Files/Dev-Cpp/include/boost/bind/bind_template.hpp:18:
error: no
   type named `type' in `struct
   boost::_bi::result_traits<boost::_bi::unspecified,
PrintAux<std::vector<int,
   std::allocator<int> >, 1> >'
E:/Program
Files/Dev-Cpp/include/boost/bind/bind_template.hpp:24:
error: no
   type named `type' in `struct
   boost::_bi::result_traits<boost::_bi::unspecified,
PrintAux<std::vector<int,

   std::allocator<int> >, 1> >'
E:/Program
Files/Dev-Cpp/include/boost/bind/bind_template.hpp:30:
error: no
   type named `type' in `struct
   boost::_bi::result_traits<boost::_bi::unspecified,
PrintAux<std::vector<int,
   std::allocator<int> >, 1> >'
E:/Program
Files/Dev-Cpp/include/boost/bind/bind_template.hpp:30:
confused by earlier errors, bailing out

make.exe: *** [Print.o] Error 1

Execution terminated

                
___________________________________________________________
24 FIFA World Cup tickets to be won with Yahoo! Mail http://uk.mail.yahoo.com


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