草庐IT

template-id

全部标签

c++ - 特定于线程的数据——为什么我不能只使用带有线程 ID 的静态映射?

在阅读POSIX线程时,我遇到了一个线程特定数据的示例。我确实有一个困惑的地方......线程特定的数据接口(interface)看起来有点笨拙,尤其是当你混合使用pthread_once、各种初始化程序等时。有什么理由我不能只使用静态std::map,其中键是pthread_self()id,数据值保存在std::pair的第二部分?我想不出只要它被包裹在互斥量中就无法工作的原因,但我没有看到任何关于它的建议或任何类似的东西让我感到困惑,因为它听起来比提供的API容易得多。我知道线程可能有很多catch-22,所以我想我会问一下,看看我是否要介入……一些不愉快的事情?:)

c++ - gcc4 模板错误或更可能是 id10t 错误

以下代码在VisualStudio下编译得很好,但gcc4.6.2或4.7都不能处理它。它似乎是有效的,但gcc似乎无法解决const和非const参数之间的区别。这可能是编译器错误吗?structCReadType{};structCWriteType{};templatestructAddPkgrConstByType{};templatestructAddPkgrConstByType{typedefTtype;};templatestructAddPkgrConstByType{typedefTtype;};templatestructAddPkgrConstByType{ty

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++ - 最令人烦恼的解析是否带有合格的 id?

考虑:structFoo{enum{bar};explicitFoo(int){}};structBaz{explicitBaz(Foo){}};Bazb(Foo(Foo::bar));//#1即使Foo::bar是一个qualified-id并且不可能是一个有效的参数名称,第1行是最令人烦恼的解析吗?ClangandGCCdisagree;哪个编译器是正确的? 最佳答案 Clang是对的。有点令人惊讶的是,parameter-declaration的语法允许qualified-和unqualified-id,因为它接受所有声明符:

无法使用共享首选项从JSON获取用户ID

JSON数据{VerifiedMember:[{user_id:"23",first_name:"karan",phone:""}],success:1,message:"success"}登录活动类publicclassNewLoginextendsAppCompatActivity{privatestaticfinalStringPREFER_NAME="Reg";ButtonbtnLogin;privateEditTexteditTextUserName;privateEditTexteditTextPassword;privateProgressDialogpDialog;JSONPa

Kotlin不拾取资源ID

我正在尝试使用Kotlin开发一个应用程序。我阅读了仅通过使用Kotlin扩展名直接引用ID来不使用FindViewByID的可能性。我已经正确应用了该插件:applyplugin:'com.android.application'applyplugin:'kotlin-android'applyplugin:'kotlin-android-extensions'在我的build.gradle上但是,当我尝试引用以下方式时:kotlinx.android.synthetic.main.item_event.view.event_coverAndroidStudio仅识别直到视图部分,也就是说k

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