Boost logo

Boost Users :

From: Suresh T (suresh.t_at_[hidden])
Date: 2005-08-08 03:22:01


hi

I am using the boost::enable_if for selection of types. Something similar
to below

template<std::size_t Size,class Enable = void>
struct type_select{
};

template<std::size_t Size>
struct type_select< Size,
                        typename boost::enable_if < bool_ < (size <= 8) >
>
>::type
>{
  typedef typename char type;
};

template<std::size_t Size>
struct type_select< Size,
                        typename boost::enable_if < bool_ < (size > 8) > >
>::type
>{
  typedef typename int type;
};

The conditions are based on the first parameter size. The normal usage
would be something like type_select<10>::type;

My question is : If i explicitly use the second parameter ( by passing
void) will the correct specialization be still used
i.e, if i use say type_select<6,void>::type, will it resolve to
"char" in the above case.

Please note: I was using the normal way (without the void) for my code
on linux+gcc without any problems
My problem came up when i tried to move my code to windows + vc7.1.
The vc7.1 compiler needs the second argument (in my usage shown below )
else it gives an error. The results are as desired, but i would like
to know whether this usage is correct.

Below is a snippet where the vc7.1 compiler gives a problem with the
usage.
Note type_select is not directly used but is used as a default type for
USER_TYPE parameter

template <std::size_t size ,
         template<std::size_t size,typename E = void > class USER_TYPE
>
class my_class
          < size,
           USER_TYPE = select_type //select_type is a default parameter
> {

public:
       //The commented code line below does not work for VC7.1
       // typedef typename USER_TYPE<size>::type data_type; //THIS
DOES NOT WORK with vc7.1

       typedef typename USER_TYPE<size,void>::type data_type; //THIS
WORKS

};
 
Thanks for clarification in advance..

---------------------------------------------------------------------------------------------------------
Rgds,
Suresh



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