Boost logo

Boost Users :

From: Hicham Mouline (hicham_at_[hidden])
Date: 2008-05-01 13:59:47


I see. Perfectly clear now.I had obviously forgotten about scope
resolution for types.
Best Regards,ps: one unrelated question to follow in a separate post :-)

  ----- Original Message -----
  From: "Ovanes Markarian"
  To: boost-users_at_[hidden]
  Subject: Re: [Boost-users] boost::result_of error?
  Date: Thu, 1 May 2008 19:45:45 +0200

  Please read below. Just got an angry email from some pedantic
  Mailing-List guard.

  On Thu, May 1, 2008 at 6:07 PM, Hicham Mouline <hicham_at_[hidden]>
  wrote:

    Thanks for your clarifications, In your example, if "MyFunc" was
    typedef'd before its use in the template argument as say typedef
    int (*MyFunc)(int);
    it would not conflict with its use in the template argument ?

  First of all. I am sorry for an error I made when stated:

  template<T MyFunc()>
  struct X
  {
  typedef T result_type;
  typedef MyFunc function_type;
  };

  This is not a valid C++ code, since MyFunc as the template parameter
  is a real pointer to a function, it is not a type. And you cannot
  make a typedef for a pointer. Only for it's type.

  To visualize the usage I have written a small program:

  #include <iostream>
  #include <typeinfo>

  typedef int (*MyFunc)(int, int);

  int get_int(int x)
  {
  return x;
  }

  int plus(int x, int y)
  {
  return x+y;
  }

  template<int (*MyFunc)(int)>
  struct X
  {
  typedef int result_type;

  result_type exec()const
  {
  ::MyFunc f2 = &plus; //use scope resolution to access the global
  MyFunc
  return MyFunc(10)+f2(10,10);
  }
  };

  int main(int argc, char* argv[])
  {
  X<&get_int> x;
  std::cout << "sum: " << x.exec() << "\n";
  }



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