我正在寻找一种快速计算3D Morton数的方法.这个网站有一个基于幻数的技巧,可以用于2D Morton数字,但是如何将它扩展到3D似乎并不明显.
所以基本上我有3个10位数字,我想用最少的操作交错成一个30位数.
我基本上希望为通用C函数生成包装器,而无需手动指定类型.所以我有一个带有固定原型的回调,但是我需要根据包装函数的类型在包装器中做一些特殊的代码......所以基本上我在考虑在类模板中使用静态方法将我的函数包装到一致的接口,例如:
// this is what we want the wrapped function to look like
typedef void (*callback)(int);
void foobar( float x ); // wrappee
// doesn't compile
template< T (*f)(S) > // non-type template param, it's a function ptr
struct Wrapper
{
static void wrapped(int x)
{
// do a bunch of other stuff here
f(static_cast<S>(x)); // call wrapped function, ignore result
}
}
Run Code Online (Sandbox Code Playgroud)
然后我想做一些像:
AddCallback( Wrapper<foobar>::wrapped );
Run Code Online (Sandbox Code Playgroud)
但是,问题是我不能继续在Wrapper模板中的函数参数中使用"S",我必须先将其列为参数:
template< class T, class S, T (*f)(S) >
struct Wrapper
// ... …Run Code Online (Sandbox Code Playgroud)