Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Removing __unaligned specifier partial solution
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64 #include <utility> template<class T> struct is_aligned_helper : std::true_type {}; template<class T> struct is_aligned_helper<__unaligned T> : std::false_type {}; template<class T , class = std::enable_if<std::is_pointer<T>::value>> struct is_aligned : is_aligned_helper<typename std::remove_cv_t<std::remove_pointer_t<T>>> {}; template<class T> using is_aligned_v = typename is_aligned<T>::value; template <class T> struct remove_aligned_helper { using type = T; }; template <class T> struct remove_aligned_helper<__unaligned T> { using type = T; }; template <class T, class = std::enable_if<std::is_pointer<T>::value>> struct remove_aligned { using type = std::add_pointer_t< typename remove_aligned_helper< std::remove_pointer_t<T>>::type>; }; template <class T> using remove_aligned_t = typename remove_aligned<T>::type; template <class To, class From, class = std::enable_if<std::is_pointer<From>::value>> constexpr To aligned_cast(From &value) noexcept { return reinterpret_cast<To>(const_cast< remove_aligned_t<From>> (value)); } int main(int, char**) { using AType = int __unaligned *; int a_data = 9; AType a = &a_data; int *aa = aligned_cast<int *>(a); using BType = const int __unaligned *; const int b_data = 3; BType b = &b_data; const int *bb = aligned_cast<const int *>(b); //int *bbb = aligned_cast<int *>(b); <-- loses const qualifier using CType = remove_aligned<AType>::type; static_assert(is_aligned<CType>::value,""); return 0; }
run
|
edit
|
history
|
help
0
MSVC alias template
javascritp
PreprocessorVsNamespace
Wide string conversion with multibyte chars and locale
wrong up
MSVC initializer code
hangman
Sorting algorithm comparison
infix to postfix v 3.0 with improved eval()
Zero