在C++ 11中,我正在使用它
typeid(T).name()
Run Code Online (Sandbox Code Playgroud)
对于我自己的哈希计算.我不需要在程序运行或编译之间使结果相同.我只需要它对于类型是唯一的.我知道,它可以为不同类型的返回相同的名称,但它通常是常量,指针等.在我的情况下,T仅仅是class XY,struct XX或派生类型.
在这种情况下,我可以假设,这T将是独一无二的吗?
我有一个类,它具有指向内核函数的函数指针,可以从外部改变.
class Bar
{
public:
int i;
}
class Foo
{
public:
std::function<double()> kernel;
Bar bar;
};
int main()
{
Foo f;
f.kernel = []() -> double { return i * i; }; //this is not working obviously
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能实现"呈现"的行为,例如.读取lambda中的类变量.我可以通过传入f内部并写入来绕过它f.bar.i,但这不是一个很好的解决方案.
在C ++ 11中,我使用它std::next是因为如果要更改vector为list,则不必更改其余代码。
对于list,std::next为O(n),因为我需要遍历所有元素。但是,这如何vector呢?我在cppreference上发现了这个注释:
但是,如果满足
InputIt或ForwardIt额外满足LegacyRandomAccessIterator的要求,则复杂度是恒定的。
是否vector符合这些要求?以及为什么“传统”?
我有源和结果图像.我知道,在源上使用了一些卷积矩阵来得到结果.可以计算这个卷积矩阵吗?或者至少不完全一个,但非常相似.
如何调整图像大小(使用HTML5 canvas元素)并保留原始图像中的EXIF信息?我可以从原始图像中提取EXIF信息,但我不知道如何将其复制到已调整大小的图像.
这是我检索调整大小的图像数据以发送到服务器端代码的方法:
canvas.toDataURL("image/jpeg", 0.7);
Run Code Online (Sandbox Code Playgroud)
对于EXIF检索,我使用的是exif.js库.
在我的应用程序中,我在平面上渲染平面.下平面具有Z = 0,第二平面具有Z = 0.5.如果我渲染它们(低于第一个),我会丢失部分渲染,如图所示

在iPhone 4和桌面(使用ES模拟器),一切都正确,没有问题.什么可能导致这个问题?
对于场景的其他部分也会出现同样的问题,例如轨道,管道(此图片上的绿色和蓝色).当我移动相机时出现问题
在我的回调系统中,我想std::function用不同的参数存储(或其他东西).
例:
void() void(int, int)我希望1)和2)存储在同一个变量中,并选择在执行调用中调用的内容
FunctionPointer f0;
FunctionPointer f2;
f0();
f2(4, 5);
Run Code Online (Sandbox Code Playgroud)
可以这样做吗?或者我必须根据输入参数计数创建几个"FuntionPointer"模板.
编辑
有可能以某种方式利用std :: bind来完成这项任务吗?使用std :: bind我可以拥有std::function<void()> f = std::bind(test, 2, 5);
编辑2
实际用例:我有一个触发系统,我想为动作分配功能指针,所以当动作发生时,调用函数.伪码样本:
structure Trigger
{
Function f;
}
Init:
Trigger0.f = pointer to some function ()
Trigger1.f = pointer to some function (a, b)
Input:
Find Trigger by input
if (in == A) Trigger.f();
else Trigger.f(10, 20)
Run Code Online (Sandbox Code Playgroud)
或者如果可能的话
Input:
Find Trigger by input
if (in == A) f = bind(Trigger.f); …Run Code Online (Sandbox Code Playgroud) 我有这个代码:
struct Foo
{
int print(int a, double b);
int print(int a);
void print();
void print(int a, int b, int c);
void other();
};
Run Code Online (Sandbox Code Playgroud)
我可以打电话
decltype(&Foo::other)
Run Code Online (Sandbox Code Playgroud)
但是打电话
decltype(&Foo::print)
Run Code Online (Sandbox Code Playgroud)
以错误告终,这对我来说很清楚.
但是我怎样才能更加"密切"地指定print我要解决的四种方法中的哪一种decltype呢?
我想进一步使用它
template <class MT>
struct method_info;
template <class T, class Res, class... Args>
struct method_info<Res(T::*)(Args...)>
{
typedef std::tuple<Args&&...> args_tuple;
typedef T ClassType;
typedef Res RetVal;
};
template <class MethodType>
void func() {
typedef method_info<MethodType> MethodInfo;
.....
}
func<decltype(&Foo::other)>();
....
Run Code Online (Sandbox Code Playgroud) c++ templates template-specialization variadic-templates c++11
我有一个可变的类模板
template <size_t ...T>
struct Foo
{
std::vector<size_t> t;
bool IsEqual()
{
//??
}
};
Run Code Online (Sandbox Code Playgroud)
我想用它们:
Foo<1,2,3,4> foo;
foo.data = {1,2,3,4};
foo.IsEqual();
Run Code Online (Sandbox Code Playgroud)
IsEqual如果元素与模板参数的顺序相同,我如何实现迭代和比较向量的每个元素并返回false/true?
我使用constexpr在编译时计算哈希码.代码编译正确,运行正常.但我不知道,如果哈希值是编译时间或运行时间.如果我在运行时跟踪代码,我不会进入constexpr函数.但是,即使对于运行时值也不会跟踪它们(计算运行时生成的字符串的哈希值 - 相同的方法).我试图调查反汇编,但我完全不理解它
出于调试目的,我的哈希码只是字符串长度,使用:
constexpr inline size_t StringLengthCExpr(const char * const str) noexcept
{
return (*str == 0) ? 0 : StringLengthCExpr(str + 1) + 1;
};
Run Code Online (Sandbox Code Playgroud)
我有像这样创建的ID类
class StringID
{
public:
constexpr StringID(const char * key);
private:
const unsigned int hashID;
}
constexpr inline StringID::StringID(const char * key)
: hashID(StringLengthCExpr(key))
{
}
Run Code Online (Sandbox Code Playgroud)
如果我在程序main方法中这样做
StringID id("hello world");
Run Code Online (Sandbox Code Playgroud)
我得到了这个反汇编代码(它的一部分 - 内联方法和其他东西中有很多东西)
;;; StringID id("hello world");
lea eax, DWORD PTR [-76+ebp]
lea edx, DWORD PTR [id.14876.0]
mov edi, eax
mov …Run Code Online (Sandbox Code Playgroud)