#pragma once #include #include // ============================ // 1. 递归去除每一层顶层 const // 效果:深度去除所有 const // ============================ template struct remove_recursive_top_const { using type = std::remove_const_t; }; template using remove_recursive_top_const_t = typename remove_recursive_top_const::type; // pointer template struct remove_recursive_top_const { using type = remove_recursive_top_const_t*; }; template struct remove_recursive_top_const { using type = remove_recursive_top_const_t*; }; template struct remove_recursive_top_const { using type = remove_recursive_top_const_t* volatile; }; template struct remove_recursive_top_const { using type = remove_recursive_top_const_t* volatile; }; // lvalue reference template struct remove_recursive_top_const { using type = remove_recursive_top_const_t&; }; // rvalue reference template struct remove_recursive_top_const { using type = remove_recursive_top_const_t&&; }; // array with known bound template struct remove_recursive_top_const { using type = remove_recursive_top_const_t[N]; }; // array with unknown bound template struct remove_recursive_top_const { using type = remove_recursive_top_const_t[]; }; // member pointer template struct remove_recursive_top_const { using type = remove_recursive_top_const_t C::*; }; template struct remove_recursive_top_const { using type = remove_recursive_top_const_t C::*; }; template struct remove_recursive_top_const { using type = remove_recursive_top_const_t C::* volatile; }; template struct remove_recursive_top_const { using type = remove_recursive_top_const_t C::* volatile; }; // ============================ // 2. 递归去除底层 const // 保留最外层 const // ============================ template struct remove_recursive_low_const { using type = T; }; template using remove_recursive_low_const_t = typename remove_recursive_low_const::type; // pointer template struct remove_recursive_low_const { using type = remove_recursive_top_const_t*; }; template struct remove_recursive_low_const { using type = remove_recursive_top_const_t* const; }; template struct remove_recursive_low_const { using type = remove_recursive_top_const_t* volatile; }; template struct remove_recursive_low_const { using type = remove_recursive_top_const_t* const volatile; }; // lvalue reference template struct remove_recursive_low_const { using type = remove_recursive_top_const_t&; }; // rvalue reference template struct remove_recursive_low_const { using type = remove_recursive_top_const_t&&; }; // array template struct remove_recursive_low_const { using type = remove_recursive_top_const_t[N]; }; template struct remove_recursive_low_const { using type = remove_recursive_top_const_t[]; }; // member pointer template struct remove_recursive_low_const { using type = remove_recursive_top_const_t C::*; }; template struct remove_recursive_low_const { using type = remove_recursive_top_const_t C::* const; }; template struct remove_recursive_low_const { using type = remove_recursive_top_const_t C::* volatile; }; template struct remove_recursive_low_const { using type = remove_recursive_top_const_t C::* const volatile; };