I can not understand why this project uses the is_default_manageable construction. It seems that in it the conditional expression in std::is_same identically executed as true .

Code snippets from this project:

 template<class T> void default_delete(T *p) SPIMPL_NOEXCEPT { delete p; } template<class T> struct default_deleter { using type = void (*)(T*); }; template<class T> using default_deleter_t = typename default_deleter<T>::type; template<class T, class D> struct is_default_manageable: public std::integral_constant <bool, std::is_same<D, default_deleter_t<T>>::value> {}; 

The class itself, I bring to the k, the accepting deleter and the second without him, use the default

 template<class T, class Deleter = details::default_deleter_t<T>> class impl_ptr { using pointer = T*; using element_type = T; using copier_type = typename std::decay<Copier>::type; using deleter_type = typename std::decay<Deleter>::type; using unique_ptr_type = std::unique_ptr<T, deleter_type>; using is_default_manageable = details::is_default_manageable<T, deleter_type>; template<class D> impl_ptr(pointer p, D&& d, typename std::enable_if< std::is_convertible<D, deleter_type>::value, dummy_t_ >::type = dummy_t_()) : ptr_(std::move(p), std::forward<D>(d)) {} template<class U> impl_ptr(U* u, typename std::enable_if<std::is_convertible<U*,pointer>::value && is_default_manageable::value, dummy_t_ >::type = dummy_t_()) : impl_ptr(u, &details::default_delete<T>, &details::default_copy<T>) {} }; 

Something removed, copier for example, so as not to copier question with similar code.

  • First, why would it suddenly is_same identically true ? I do not see any identity here. Secondly, in the second piece of code some kind of nonsense is written. Why are the parameters for is_default_manageable not specified? - AnT
  • @AnT added a line with a pseudonym, forgot to copy from the original project. - Jenssen
  • OK. AND? Where is the identity here? Why did you decide that deleter_type always identical to default_deleter ? - AnT
  • @AnT So same as the default argument. I do not understand how and why this construction works? - Jenssen
  • one
    The second constructor must be disabled in order to force the user to specify exactly two parameters in the constructor. If it is not disabled, it will be possible for the user to accidentally forget to specify the deleter value (since the second constructor requires only one parameter). - AnT

0