我刚刚通过使用C++ 11可变参数模板在编译时对其进行评估来实现快速排序算法.但是,当数据集太大时,我遇到性能问题.
#include <iostream>
using namespace std;
template<int... vs>
struct Seq
{};
template<int v1, int...vs>
struct Seq<v1, vs...>{
};
template<typename newT, typename srcT>
struct PushFront{
};
template<int vadded, int...vs>
struct PushFront<Seq<vadded>, Seq<vs...>>{
typedef Seq<vadded, vs...> ResultType;
};
template<typename T>
struct PopFront{
};
template<int v1, int...vs>
struct PopFront<Seq<v1, vs...>>{
typedef Seq<vs...> RemaindType;
typedef Seq<v1> ResultType;
};
template<typename T1, typename T2>
struct CatSeq{};
template<int...v, int...us>
struct CatSeq<Seq<v...>, Seq<us...>>{
typedef Seq< v..., us... > ResultType;
};
template<bool c, typename NewT, typename TrueClsT, typename …
Run Code Online (Sandbox Code Playgroud) c ++编译器如何在C++ 0x中实现线程本地存储
我在谷歌搜索过这个.但我找不到任何关于此事的内容.
有没有人对此有任何材料?
如何在python中找出导入特定文件的文件?
请考虑以下示例:
#a.py
import cmn
....
#b.py
import cmn
...
#cmn.py
#Here, I want to know which file (a.py or b.py)
#is importing this one.
#Is it possible to do this?
...
Run Code Online (Sandbox Code Playgroud)
所有文件a.py
,b.py
并cmn.py
在同一个目录下.
我为什么要这样做?
在C/C++中,它们具有包含功能.我想做的事情可以通过C/C++代码来阐明.
//a.cpp
....
#define SOME_STUFF ....
#include "cmn.h"
//b.cpp
...
#define SOME_STUFF ....
#include "cmn.h"
//cmn.h
//Here, I'll define some functions/classes that will use the symbol define
//in the a.cpp or b.cpp
...
....code refer to the SOME_STUFF.....
Run Code Online (Sandbox Code Playgroud)
在C/C++中,我们可以使用此方法来重用sourecode.
现在返回我的python代码. …
如何为函数调用转储候选函数(或可行函数或最佳可行函数)?
我知道g ++提供了转储类层次结构的选项.(事实上,Visual Studio 2010提供了类似的选项,但它没有文档.我记得读过一些关于它的内容 - 也许是在VC++团队博客中 - 但我不记得清楚了.)
最近,我一直在阅读关于C++ 0x草案中的重载解析,这让我很尴尬.
是否有任何编译器提供转储候选函数,可行函数或最佳可行函数的选项?
注意:重载决策场景中的候选函数与编译器错误中的候选函数不同.超载解决方案中的候选/可行/最佳可行功能具有其自身的含义.我知道他们在重载决策中有三个阶段:找到候选函数; 找到可行的功能; 找到最好的可行功能.通常,最好的可行功能只是一个候选者; 否则,电话是不明确的.每个阶段都有自己的规则.
在C++ 0x中,我们使用std::function
如下所示:
int normal_function() {
return 42;
}
std::function<int()> f = normal_function;
Run Code Online (Sandbox Code Playgroud)
因此,要获得一个std::function
实例,我们必须首先定义它的类型.但它很无聊,有时很难.
那么,我们可以使用make来获取std::function
实例std::tuple
吗?
事实上,我只是谷歌搜索,C++ 0x不提供这样的make工具.
为什么C++ 0x没有提供make工具?我们可以实施吗?
这些天我在C中找到了一个博客提到的中止功能.
以下是中止功能的源代码:http: //cristi.indefero.net/p/uClibc-cristi/source/tree/0_9_14/libc/stdlib/abort.c
我发现它使用hlt
指令(我的电脑是x86).
但似乎hlt
必须在第0环中运行.(请参阅wiki http://en.wikipedia.org/wiki/HLT)
似乎中止正在用户空间中运行.因此hlt
,中止使用该指令似乎是非法的.
顺便说一下,我尝试hlt
在linux和windows中运行.但我遇到了一个错误.
在linux中:
#include <iostream>
using namespace std;
#define HLT_INST asm("hlt")
int main(){
cout<<"whill run halt"<<endl;
HLT_INST; //result in SIGSEGV error
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在Windows中:
cout<<"will run hlg"<<endl;
/*Unhandled exception at 0x0040101d in test_learn.exe: 0xC0000096: Privileged instruction.
*/
__asm{
hlt;
}
Run Code Online (Sandbox Code Playgroud)