vendredi 21 avril 2017

Is there something like std::remove_const_reference in type_traits

There ale some functions in std C++ library that are able to modify types, like std::remove_reference or std::remove_cv. I wonder if/why not there is something like std::remove_const_reference, for example:

#include <iostream>
#include <type_traits>

template <typename T>
using remove_cref_t = typename std::remove_const<typename std::remove_reference<T>::type>::type;

template <typename T>
void linker_test_type();

int main() {
    using type = int volatile const&;
    test<remove_cref_t<type>>();
    return 0;
}

The expected output is of course:

undefined reference to `void linker_test_type<int volatile>()'

Aucun commentaire:

Enregistrer un commentaire