我最近停止使用,macports因此我用于各种IPython内核的kernel.json文件已经过时了.我已重命名~/.ipython并删除了,~/.jupyter但启动的内核无法启动file not found错误.
更有说服力的是,当我运行时,jupyter-kernelspec list它仍然列出了我设置的所有旧内核.从哪里获取此信息以及我需要做什么来刷新/删除其缓存?
最近,来自Concepts TS的C++概念已合并到GCC主干中.概念允许人们通过要求类型来满足概念的条件(例如"可比较")来约束通用代码.
Haskell有类型类.我对Haskell并不熟悉.概念和类型类是如何相关的?
我有一个简单的项目,我想调试想生成带调试符号的dSYM文件夹.
运行:
clang++ -std=c++14 -stdlib=libc++ -g -o Lazy Lazy.cpp
像我期望的那样创建Lazy.dSYM.
然而:
clang++ -std=c++14 -stdlib=libc++ -g -c Lazy.cpp
clang++ -stdlib=libc++ -g -o Lazy Lazy.o
Run Code Online (Sandbox Code Playgroud)
不创建Lazy.dSYM(似乎符号嵌入在二进制文件中).
遗憾的是,两步构建是我修改后的makefile所做的.如何从两阶段编译和链接构建生成Lazy.dSYM?
我不需要 dSYM目录,只需调试符号,但想了解它的创建时间和原因.
我想用来boost::uuids::detail::sha1为大型二进制blob创建一个哈希.
sha1在detail命名空间中,因此不应该"依赖".如何在不实例化对象的情况下为我的blob创建SHA1哈希detail?
我怀疑一些ASSERTION代码有副作用.我想关闭ASSERT,而不对我的代码编译方式进行任何其他更改.我正在使用MSVS2008.从调试切换到发布不会这样做会改变内存的初始化方式.
我有一个在堆上使用内存的函数,如果在同一个函数的另一个实例完成之前调用它将会出现严重错误.如何在编译时防止这种情况发生?
我创建了一个不可复制的地图,我无法用clang编译.由于clang符合标准,我想知道我的代码是否合法.MSVS 2010和GCC 4.7编译此代码时没有警告或错误.
附上完整的代码:有问题的行是最后一行main.
= delete 需要删除MSVS 2010
#include <utility>
#include <iostream>
#include <map>
template<typename Key_t, typename Value_t, typename Compare_t = std::less<Key_t> >
class non_copyable_map : public std::map<Key_t,Value_t,Compare_t>
{
typedef std::map<Key_t,Value_t,Compare_t> BaseType;
public:
non_copyable_map() { }
non_copyable_map(non_copyable_map&& t) : BaseType(std::move(t)) {}
non_copyable_map& operator = (non_copyable_map&& t)
{
if ( this != &t )
{
std::swap<BaseType>(*this,t);
}
return *this;
}
private:
non_copyable_map(const non_copyable_map&) = delete;
non_copyable_map& operator = (const non_copyable_map&) = delete;
};
int main(int argc, char* argv[])
{ …Run Code Online (Sandbox Code Playgroud) 我对std::is_const将const指针识别为非的行为感到困惑const.我自己的实现is_const完全一样.我不确定为什么<T>在<const T>版本上挑选更通用的模板化结构.gcc4.7和clang3.1-svn都表现出相同的行为.谁能解释一下发生了什么?代码如下:
#include <iostream>
#include <sstream>
#include <type_traits>
class CEmptyClass {};
namespace jbc
{
template <typename T>
struct is_const : std::false_type {};
template <typename T>
struct is_const<const T> : std::true_type {};
}
int main(int argc, char* argv[])
{
std::cout << "Is 'const CEmptyClass*' constant according to std lib : "
<< std::is_const<const CEmptyClass*>::value << std::endl;
std::cout << "Is 'const CEmptyClass*' constant according to jbc : "
<< jbc::is_const<const …Run Code Online (Sandbox Code Playgroud) 以下代码在OS X上使用来自macports的clang 2.8编译,在下面给出了缺少的符号错误.
#include <iostream>
int main()
{
std::cout << "hello world" << std::endl;
}
jonathancoe@MacBookCoe:/tmp$ clang HW.cpp
Undefined symbols:
"__ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc", referenced from:
_main in cc-C9ObsA.o
"__ZNSt8ios_base4InitC1Ev", referenced from:
___cxx_global_var_init in cc-C9ObsA.o
"__ZNSt8ios_base4InitD1Ev", referenced from:
___cxx_global_var_init in cc-C9ObsA.o
"__ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_", referenced from:
_main in cc-C9ObsA.o
"__ZNSolsEPFRSoS_E", referenced from:
_main in cc-C9ObsA.o
"__ZSt4cout", referenced from:
_main in cc-C9ObsA.o
ld: symbol(s) not found
Run Code Online (Sandbox Code Playgroud)
简单的程序使用g ++很好地链接,没有任何额外的参数.任何想法,我可以做什么来得到这个程序链接或解释为什么不可能(如果是这种情况)?
我一直在阅读并编写Anthony Williams的书" Concurrency in Practice "中的示例,并且需要为gcc4.8启用双字比较和交换,-mcx16以便包含指针int的结构可以在锁中操作 - 免费的原子方式.
Clang(任何版本)是否支持x64上的双字比较和交换?
以下代码给出了GCC4.8和Clang 3.3中的链接错误,没有额外的编译器选项:
#include <atomic>
#include <thread>
struct ReferenceCountedPointer
{
int referenceCount;
void* data;
};
int main()
{
std::atomic<ReferenceCountedPointer> arcp;
ReferenceCountedPointer rcp;
arcp.compare_exchange_weak(rcp, rcp);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
上面的程序毫无意义,但说明了我看到的链接错误.
我用于Clang和GCC的编译命令是:
Clang 3.3:
clang++-mp-3.3 -std=c++11 -stdlib=libc++ CX16.cpp -o CX16
Run Code Online (Sandbox Code Playgroud)
失败:
Undefined symbols for architecture x86_64:
"___atomic_compare_exchange", referenced from:
_main in CX16-plVSvq.o
ld: symbol(s) not found for architecture x86_64
Run Code Online (Sandbox Code Playgroud)
GCC4.8:
g++-mp-4.8 -std=c++11 CX16.cpp -o CX16
Run Code Online (Sandbox Code Playgroud)
失败:
Undefined symbols for architecture x86_64:
"___atomic_compare_exchange_16", referenced …Run Code Online (Sandbox Code Playgroud) C++如何确保为堆栈分配的对象调用析构函数?当我分配动态内存时,析构函数(或指向它的指针)会发生什么,如下所示:
class MyClass {
public:
~MyClass()
{
std::cout<<"Destructor called."<<std::endl;
}
MyClass()
{
std::cout<<"Constructor called."<<std::endl;
}
};
....................................................................
//Limit scope for example
{
MyClass instance;
}
Run Code Online (Sandbox Code Playgroud)
构造函数和析构函数都被调用.这里发生了什么?
我有以下 Swift 课程:
public class Tree {
var obj_ : OpaquePointer
public init(fromCPtr obj:OpaquePointer) {
obj_ = obj
}
convenience init(_ levels:Int32) {
var rv : OpaquePointer?
Tree_Tree_create(levels, &rv)
self.init(fromCPtr:rv!)
}
deinit
{
Tree_Tree_dispose(obj_)
}
}
Run Code Online (Sandbox Code Playgroud)
以及以下测试代码:
import Foundation
import Tree
let t = Tree(4)
print(t.data())
Run Code Online (Sandbox Code Playgroud)
我用以下命令编译 Tree 模块:
swiftc Tree.swift -import-objc-header Tree-Bridging-Header.h -L. -lTree_c -emit-module -emit-module-path build/Tree.swiftmodule -emit-library -module-name Tree -o build/Tree
Run Code Online (Sandbox Code Playgroud)
这可以正常工作,不会出现错误或警告。
我用以下方法编译我的测试代码:
swiftc TestTree.swift -Ibuild/
Run Code Online (Sandbox Code Playgroud)
并得到以下错误:
TestTree.swift:4:14: error: cannot convert value of type 'Int' to expected argument …Run Code Online (Sandbox Code Playgroud)