40 lines
1.0 KiB
C++
40 lines
1.0 KiB
C++
/// Josh's 3D Math Library
|
|
/// A C++20 Library for 3D Math, Computer Graphics, and Scientific Computing.
|
|
/// Developed and Maintained by Josh O'Leary @ Redacted Software.
|
|
/// Special Thanks to William Tomasine II and Maxine Hayes.
|
|
/// (c) 2024 Redacted Software
|
|
/// This work is dedicated to the public domain.
|
|
|
|
/// @file Reinterpret.h
|
|
/// @desc Reinterpret one type to another using union hackery.
|
|
/// @edit 2024-07-06
|
|
|
|
#pragma once
|
|
|
|
|
|
namespace J3ML
|
|
{
|
|
|
|
/// As per C99, union-reinterpret should now be safe: http://stackoverflow.com/questions/8511676/portable-data-reinterpretation
|
|
template <typename To, typename From>
|
|
union ReinterpretOp {
|
|
From from;
|
|
To to;
|
|
|
|
|
|
ReinterpretOp(From from_) : from(from_) {} // Do not make explicit!
|
|
operator To() const { return to; } // Do not make explicit!
|
|
};
|
|
|
|
|
|
template <typename To, typename From>
|
|
To ReinterpretAs(From input)
|
|
{
|
|
//ReinterpretOp<To, From> fi;
|
|
//fi.to = input;
|
|
return ReinterpretOp<To, From>(input); //fi.from;
|
|
}
|
|
|
|
|
|
|
|
} |