mercredi 31 octobre 2018

Is there a way to alter a type using type_traits within a template parameter list?

template
<
    template <typename, typename, typename>
        class storage_t,
    typename _Tp = storage::unknown_type,
    typename is_allocated = std::false_type
>
struct Example_Buffer:
    public Buffer<storage_t, _Tp, is_allocated> { ... };

In this code, I want to remove the reference, if _Tp has one. I do not want to use typename = std::enable_if_t<std::is_reference_v<_Tp>>, because I do want the program to compile if _Tp is a reference, but I would like to remove it in that case. I thought of a solution, but it did not seem ideal:

template
<
   template <typename, typename, typename>
        class storage_t,
    typename _Tp = storage::unknown_type,
    typename is_allocated = std::false_type,
    typename _Tp2 = std::remove_reference_t<_Tp>
>
struct Example_Buffer { ... };

Is there a better way to do this? Feel free to ask if I need to elaborate.

Aucun commentaire:

Enregistrer un commentaire