首页
\
问答
\
什么样的C ++模板编程可以称为“元编程”?(What kind of C++ template programming can be called “meta programming”? [closed])
什么样的C ++模板编程可以称为“元编程”?(What kind of C++ template programming can be called “meta programming”? [closed])
- 使用什么样的模板技术,可以称为“元编程”?
- 是什么和什么不是元编程有一个很好的定义?
- 我们的C ++ 11 STL是否包含大量元编程?
- 是“type_traits”元编程“?
非常感谢。
- Using what kind of template technical, could be called "meta programming"?
- Is there a good definition of what's and what's NOT meta programming?
- Does our C++11 STL contain a lot of meta programming?
- Is "type_traits" meta programming"?
Thanks a lot.
原文:https://stackoverflow.com/questions/37770194
更新时间:2023-09-13 08:09
最满意答案
在@GünterZöchbauer的帮助下,我把这件事理顺了。 因此添加return语句将解决类型不匹配问题。 这是通过编译器检查的修改代码。
loadHero1(id: number) { this.hero$ = this._cachedHeroes.map(heroes => heroes.find(hero => { return hero._id === id; } )) .catch(handleError) .map( (data : Hero) => { this._dataStore.hero = data; this._heroObserver.next(this._dataStore.hero); return data; } //error => handleError('Could not load hero.') ); }
With the help of @Günter Zöchbauer, I got this thing straighten out. So adding return statement will resolve the type mismatch. Here is the modified code that passed the compiler check.
loadHero1(id: number) { this.hero$ = this._cachedHeroes.map(heroes => heroes.find(hero => { return hero._id === id; } )) .catch(handleError) .map( (data : Hero) => { this._dataStore.hero = data; this._heroObserver.next(this._dataStore.hero); return data; } //error => handleError('Could not load hero.') ); }
相关问答
更多-
它应该是这样的: var file = files[i]; var reader: FileReader = new FileReader(); reader.onload = ((f: any) => { return (e: any) => { // some code }; })(file); It should be something like this: var file = files[i]; var reader: FileReader = new Fil ...
-
打字稿 - 功能参数中有多个类型的无效字段(typescript - invalid field in function parameter with multiple types)[2022-08-31]
您正在寻找一名可以“缩小”您的界面的警卫。 function isCustomErro(x: any): x is CustomError { return x.hasOwnProperty('errorRaw'); } 然后,您的getReport方法将如下所示: public getReport(data: SalesReport | CustomError) { if (isCustomError(data)) { throw new Error(data.errorRaw) } ... -
在@GünterZöchbauer的帮助下,我把这件事理顺了。 因此添加return语句将解决类型不匹配问题。 这是通过编译器检查的修改代码。 loadHero1(id: number) { this.hero$ = this._cachedHeroes.map(heroes => heroes.find(hero => { return hero._id === id; } )) .catch(handleErro ...
-
胖箭头=>保留封闭上下文的内容。 否则它的行为类似于普通函数表达式。 细箭头->不存在。 听起来你正在使用Webstorm,它并不总能提供100%准确的错误信息。 The fat arrow => preserves the this of the enclosing context. Otherwise it behaves like a normal function expression. The thin arrow -> does not exist. It sounds like you're ...
-
我将分两部分来分解陈述 第1部分 - 变量类型定义 let isPrime: (n: number) => boolean 是isPrime变量的类型定义。 在这种情况下, isPrime将包含一个函数: (n: number) => boolean 它接受一个类型number参数并返回一个boolean 第2部分 - 分配给isPrime变量的实际值 (在=符号后面) n => { // body }; 这是实际值,根据类型定义,它是一个带有一个参数的函数...但由于在主体中没有返回 ...
-
那么,使用泛型: function callM
(arr: T[]): void { arr.forEach(t => t.m()); } 现在你可以这样做: callM([A, B, C]); // OK callM([A, B, string]); // Error 如果你想存储这些值: class Container { public klazzes: (typeof A)[]; } const cont: Container = new Co ... -
打字稿:箭头功能 - TS2339:类型“{}”上不存在属性(Typescript: Arrow function - TS2339: Property does not exist on type '{}')[2022-09-12]
试试这个: this.data$ = this.route.params .switchMap((params: any) => Observable.forkJoin([ Observable.of(params), this.http.get('/api', { param1: params.param1, param2: params.param2 }) ]) //**Errors from this p ... -
在你的具体情况下,这并不重要。 但 如果你有严格标志(或者扩展名为noImplicitAny标志),它会为第一个,而不是第二个引发错误。 因为不允许隐含任何内容。 他们之所以相同的原因是因为TypeScript无法推断参数的类型或返回类型,所以它们都被推断为任何类型。 任何东西都是你从TypeScript中逃脱出来的,它的意思是“我不知道这是什么类型,所以我用它做的任何事情都是可以接受的,它的任何属性都隐含地存在(并且也有一种类型),我可以称之为有任何参数,我也可以new它。 建议您最小化对隐式或显式any ...
-
与Typescript反应:带有箭头功能的array.map()的类型(React with Typescript: Types for array.map() with arrow function)[2022-04-13]
您当前的ProjectItem类不接受作为其道具的project对象,但其道具由IprojetItem接口定义(即它接受作为道具的title和category )。 代替 class ProjectItem extends React.Component{ ... } 你应该写 export interface ProjectItemProps { project: IprojectItem; } class ProjectItem ex ... -
我如何使用带箭头功能的高级/嵌套类型变量?(How can I use advanced/nested type variables with arrow functions?)[2023-09-24]
如注释中所述,当通用箭头函数写入tsx文件时发生错误。 在ts中,问题中的语法运行正常。 由于语法中的模糊性,这是tsx文件中泛型的已知限制,这在此处记录 。 如链接中所建议的,您可以通过向T添加类型约束来避开它 const wrapInObject =(key: string) => (x: T) => ({ [key]: x }); As stated in the comments the error occurs when the generic arrow func ...