草庐IT

graph_templates

全部标签

c++ - 什么是 "template<class T> using owner = T;"?

以下摘自Microsoft的gsl库(https://github.com/microsoft/gsl)的gsl.h:namespacegsl{////GSL.owner:ownershippointers//usingstd::unique_ptr;usingstd::shared_ptr;templateusingowner=T;...};我无法理解以下别名模板的含义:templateusingowner=T;有什么解释吗? 最佳答案 这意味着对于每个T,owner是T的别名. 关于

C++ 等效于 Tensorflow 中的 python : tf. Graph.get_tensor_by_name()?

Python的C++等价物是什么:Tensorflow中的tf.Graph.get_tensor_by_name(name)?谢谢!这是我尝试运行的代码,但我得到一个空的输出:Statusstatus=NewSession(SessionOptions(),&session);//createnewsessionReadBinaryProto(tensorflow::Env::Default(),model,&graph_def);//readGraphsession->Create(graph_def);//addGraphtoTensorflowsessionstd::vector

C++ : friend function in a template class for operator<<

在.cpp文件中声明模板类的友元函数(对于std::ostream&运算符?我当前的实现不起作用://MyTest.htemplateclassMyTest{inlinefriendstd::ostream&operator(std::ostream&lhs,constMyTest&rhs);};//MyTest.cpptemplateinlinefriendstd::ostream&operator(std::ostream&lhs,constMyTest&rhs){//IMPLEMENTATION}非常感谢! 最佳答案 引用op

c++ - 为什么我的 Curiously Recurring Template Pattern (CRTP) 不能引用派生类的 typedef?

这个问题在这里已经有了答案:C++staticpolymorphism(CRTP)andusingtypedefsfromderivedclasses(5个答案)关闭9年前。使用curiouslyrecurringtemplatepattern时,如果我试图从基类中引用属于派生类的typedef,则仅无法引用它们;gcc提示notypenamed'myType'inclassDerived.这似乎与使用typedef、模板和奇怪的重复关系的其他方式不一致。考虑:/*crtp.cpp*/#includeusingnamespacestd;//case1.simple.classBase{

C++1y/C++14 : Converting static constexpr array to non-type template parameter pack?

假设我有一个静态存储持续时间的constexpr数组(已知范围):constexprTinput[]=/*...*/;我有一个需要打包的输出类模板:templatestructoutput_template;我想像这样实例化output_template:usingoutput=output_template;一种方法是:templatestructmake_output_template{templatestaticconstexproutput_templatef(std::index_sequence){return{};};usingtype=decltype(f(std::m

c++ - 有没有理由使用 "::template"?

从全局命名空间获取模板名称时,您可以使用template关键字:templatevoidfunction_template();templatevoidh(){::templatefunction_template();}intmain(){h();}但是这段代码可以在没有它的情况下编译。在什么情况下可能需要这样做? 最佳答案 我能想到一个地方,但我认为它不太常见:#include//simpilefunctiontemplatetemplatevoidfunction_template(T){std::cout输出voidfunc

c++ - 为什么 Boost Graph Library 的 `source()` 是一个全局函数?

我理解在泛型编程中,算法与容器是解耦的。因此,将泛型算法实现为实例方法是没有意义的(相同的算法应该适用于多个具体类;我们不想让它们都继承自一个ABC,因为这会以指数方式增加类的数量)。但在source()的情况下BoostGraphLibrary中的函数,我不明白为什么它是全局函数而不是图形类的实例方法。据我所知,我可以通过阅读BGLsourcecode来判断,source(e,g)需要知道传递给它的图和边对象的实现细节;仅仅知道它们的接口(interface)是不够的。所以source()不是通用算法。换句话说,它需要知道图形实例的具体类。那为什么不把它和实例方法放在同一个类中呢?与

c++ - reference_wrapper : make_pair VS Class Template Argument Deduction (CTAD)

为什么make_pair和类模板参数推导(CTAD)不同意生成哪种类型?#include#include#include#includeintmain(){intmyInt=5;std::reference_wrappermyIntRef=myInt;automyPair=std::make_pair(myInt,myIntRef);std::pairMy2ndPair(myInt,myIntRef);std::cout输出:St4pairIiRiE//std::pairSt4pairIiSt17reference_wrapperIiEE//std::pair>更新:为什么std::p

c++ - 嵌套模板特化结果为 "Illegal use of explicit template arguments"?

如何专门化嵌套模板?(请参阅下面的错误。)usingstd::reverse_iterator;templatereverse_iteratormake_reverse_iterator(constIt&it){returnreverse_iterator(it);}templateItmake_reverse_iterator>(constreverse_iterator&it){//Above^//errorC2768://'make_reverse_iterator':illegaluseofexplicittemplateargumentsreturnit.base();}

c++ - 在每个源文件中替代 "extern template"

我正在开发一个库,其中我们的许多核心对象都是模板,其中一个特定实例以指向该模板实例的智能指针的形式出现在项目的大多数文件中。我在单个源文件中明确实例化了这些模板。我们最近切换到C++11,我正在尝试使用新的externtemplateclassMyTemplate;加快编译速度。我的第一个问题是我是否在周围使用智能指针MyTemplate正在隐式实例化模板并要求文件顶部的“外部模板..”以避免重复实例化。我的第二个问题是是否有一些替代方法来添加所有这些externtemplateclassMyTemplate;到每个源文件。为我定义的每个模板搜索智能指针的每个实例并确保我在该文件中有正