Boost logo

Boost Users :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2005-08-29 21:46:57


On Aug 29, 2005, at 4:44 PM, Okko Willeboordse wrote:

> Peter Dimov wrote:
>> Okko Willeboordse wrote:
>>
>>
>>> So I do
>>>
>>> class some_class
>>> {
>>> public:
>>> template <class T>
>>> some_class(const boost::function1<T*, short*>& get_member)
>>
>>
>> Why not just
>>
>> template<class F> some_class( F f );
>>
>> ?
>>
>> boost::function<> is useful when you have to capture an arbitrary
>> function
>> object in a fixed type. Since your boost::function<> above is
>> templated on
>> T, it has a variable type, so you can just use the function object
>> argument
>> as-is.
>
> Thanks,
>
> Then I end up with a constructor that takes any type of data which
> can not be distinguished from my other constructors.

I'm not sure what your other constructors look like, but perhaps you
could constrain F such that there is no question that the templated
constructor will accidently bind to the wrong call. For example:

class some_class
{
public:
   some_class(int i);
   template <class T>
      template<class F> some_class( F f, typename
enable_if<!is_convertible<F, int>::value>::type* = 0);
};

-Howard


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