|
Boost Users : |
From: Yutaka Leon Suematsu (yutaka_at_[hidden])
Date: 2005-04-04 07:33:13
Hello Jaakko,
Thank you for your reply.
> The problem is that T is not a template parameter of you function f1.
> It is a template parameter of the class A.
I got it.
> class A
> {
> ...
> template <class T>
> enable_if< boost::is_arithmetic<T>, void > :: type f1()
> {
> ...
> }
> };
> Also, here you need to explicitly instantiate f1 as
>
> A a;
> a.f1<int>();
I tried this way too. Although I wanted to have only one interface, I guess
it the best possibility I have now.
Thanks a lot,
Yutaka Leon Suematsu
> Jaakko Järvi wrote:
> Hello Yutaka,
>
> The problem is that T is not a template parameter of you function f1.
> It is a template parameter of the class A. So when the class A
> is instantiated with some type that is not arithmetic, say void*,
> it is as if you would directly write a function:
>
> enable_if<boost::is_arithmetic<void*>, void>::type
>
> which is
>
> enable_if<false, void>::type
>
> which is an error, since enable_if<false,void> is an empty class.
>
> You can write your code as follows to make enable_if work, but it may
> not be a solution that works:
>
> class A
> {
> ...
> template <class T>
> enable_if< boost::is_arithmetic<T>, void > :: type f1()
> {
> ...
> }
> };
>
> Also, here you need to explicitly instantiate f1 as
>
> A a;
>
> a.f1<int>();
>
> Best, Jaakko Järvi
>
>
>
> On Apr 1, 2005, at 3:27 AM, Yutaka Leon Suematsu wrote:
>
>> Dear booster,
>>
>> I have a question related to enable_if. I would like to enable or
>> disable
>> some member functions from a template class, but enable_if is -not
>> enable-
>> to do it :-)
>>
>> Here is the code.
>>
>> template <class T>
>> class A
>> {
>> ...
>> enable_if< boost::is_arithmetic<T>, void > :: type f1()
>> {
>> ...
>> }
>> };
>>
>> In class A, I want to define function f1 only if the template
>> parameter is
>> arithmetic. It works fine except when the parameter is not
>> arithmetic. I
>> have a compile error "error C2039: 'type' : is not a member of
>> 'boost::enable_if<Cond,T>'" (Working with VC7.1, and boost 3.12)
>>
>> Thank you in advance for any suggestions and help.
>>
>> Sincerely yours,
>>
>> Yutaka Leon Suematsu
>>
>>
>>
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>
> -- Jaakko Järvi, Assistant Professor
> -- Texas A&M University, Computer Science
> -- jarvi_at_[hidden]
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