Why does the template class have an unused type?

I am looking at the boost block library, and I am puzzled by why there is an additional template parameter in the boost :: units :: unit class. Here is an example:

http://www.boost.org/doc/libs/1_57_0/boost/units/unit.hpp

template<class Dim,class System, class Enable>
class unit
{
    public:
        typedef unit<Dim, System>   unit_type;
        typedef unit<Dim,System>    this_type;
        typedef Dim                 dimension_type; 
        typedef System              system_type;

        unit() { }
        unit(const this_type&) { }
        //~unit() { }  

        this_type& operator=(const this_type&) { return *this; }

        // sun will ignore errors resulting from templates
        // instantiated in the return type of a function.
        // Make sure that we get an error anyway by putting.
        // the check in the destructor.
        #ifdef __SUNPRO_CC
        ~unit() {
            BOOST_MPL_ASSERT((detail::check_system<System, Dim>));
            BOOST_MPL_ASSERT((is_dimension_list<Dim>));
        }
        #else
    private:
        BOOST_MPL_ASSERT((detail::check_system<System, Dim>));
        BOOST_MPL_ASSERT((is_dimension_list<Dim>));
        #endif
};

The class is used to add measurements to the measurement system.

typedef unit<pressure_dimension,si::system>      pressure;

What is the purpose of “Enable” in this case?

+4
source share
1 answer

This forward"units_fwd.hpp" class template is declared in .

template<class Dim,class System, class Enable=void> class unit;

, void. template<class Dim,class System, class=void> class unit;, , , , Enable.

"" SFINAE . , 3- Dim System, ( void) .

( ; {};, ), , , .

SFINAE:

template<class T, class=void> struct is_int : std::false_type {};
template<class T> struct is_int< T,
  std::enable_if_t< std::is_same<T, int>{} >
> : std::true_type {};

false_type. , , T , , true_type.

is_int< int, void >:std::true_type{}, (, is_integral) true_type.

+5

All Articles