编译器是否可以在模板元编程中识别递归问题?(Can compilers identify recursion issues in Template Meta programming?)
在模板元编程中,如果使用结果无限循环错误地实现递归,语言编译器是否可以检测到它? 或者编译器是否会遇到最终的堆栈溢出和崩溃? 我敢打赌,编译器无法检测到这一点,因为这样做会违反暂停问题的不可预测性。
我的结论是否正确? 当然我可以用一段代码来试试这个,但我想在这种情况下听到更多合格的思考。
编辑:谢谢你们,我得到了一个普遍的想法,即我对tmp的计算理论方面的推论没有错。 我也明白,编译器实现可以有任意的递归深度限制(当然我重申我可以测试第二部分,但它只是我的一个方面)。
In Template Meta Programming if a recursion is wrongly implemented with a resulting infinite loop, can the language compiler detect it? Or will the compiler just encounter an eventual stack overflow and crashe? My bet would be that compiler cannot detect this because doing so would violate the undecideability of the halting problem.
Am I right with the conclusion? Of course I could try this out with a piece of code, but I would like to hear more qualified thinking in this case.
Edit : Thanks guys, I get a general idea that my inference on the computation theory aspect of tmp was not wrong. I also understand that compiler implementations can have arbitrary recursion depth limits(Of course I reiterate that I could have tested this second part, but it was only my side-point).
原文:https://stackoverflow.com/questions/10873179
最满意答案
每个班次都有一个
hasMany
,因此你不能在集合上调用shift_workers()
。你要循环,如下所示:
foreach ($event->shifts as $shift) { $shift->shift_workers()->saveMany($workers); }
Each shift has a
hasMany
, so you can't callshift_workers()
on a collection.You've to loop, like below:
foreach ($event->shifts as $shift) { $shift->shift_workers()->saveMany($workers); }
相关问答
更多-
Laravel hasManyThrough对中间模型有约束(Laravel hasManyThrough with constraint on intermediate Model)[2022-06-24]
如果您在Neighborhood和NeighborhoodFilter之间有一个关系,您可以使用whereHas函数。 public function neighborhoods() { return $this->hasManyThrough('Neighborhood', 'NeighborhoodFilter', 'userId', 'id')->whereHas('neighborhoodFilters', function($q){ $q->where('isActive' ... -
更改 public function producttype() { return $this->hasManyThrough('App\ProductGroup', 'App\ProductLine', 'ProductGroupId', 'ProductGroupId'); } 至 public function producttype() { return $this->hasManyThrough('App\ProductType', 'App\ProductLine', ...
-
你需要像这样http://softonsofa.com/tweaking-eloquent-relations-how-to-get-hasmany-relation-count-efficiently/只是稍微调整,以满足您的需求: public function reviewRows() { return $this->hasManyThrough('ReviewRow', 'Review'); } public function avgRating() { return $this- ...
-
不。你的hasManyThrough通气很好,但是当你调用profile_images方法时它会返回QueryBuilder实例。 要获取相关模型的集合,请使用get方法 $images = $user->profile_images()->get(); 或者只是使用laravel的“魔法” $images = $user->profile_images; No. Your hasManyThrough ralation are fine, but when you call profile_image ...
-
虽然User模型上的hasManyThrough关系没有任何问题,但在这种情况下,最好通过Order模型访问订单商品。 确保您的订单模型具有定义的关系: class Order extends Eloquent { public function order_items() { return $this->hasMany('OrderItem'); } } 现在,您的视图看起来像: @foreach($user->orders as $order) {{ $orde ...
-
Laravel hasManyThrough - 没有返回所有预期的结果(Laravel hasManyThrough - not returning all expected results)[2023-02-05]
这是一个多对多的关系。 调查模型 public function questions() { return $this->belongsToMany(Question::class, 'survey_question'); } 问题模型 public function surveys() { return $this->belongsToMany(Survey::class, 'survey_question'); } 然后你可以 $survey = Survey::with('question ... -
不确定您的表结构是否适合使用hasManyThrough 从我可以看到您需要的文档 location id - integer network_id - integer network id - integer location_id - integer owner id - integer network_id - integer name - string 然后你可以使用 return $this->hasManyThrough( 'App\O ...
-
Laravel hasManyThrough,属于其他两个模型之间(Laravel hasManyThrough, with belongs to between the other two models)[2024-02-15]
我想你不能在这里使用HasManyThrough。 在您的代码中尝试这样的事情: $store = Store::with('repairs.supplier')->find($id_store);//eager load $repairs = $store->repairs->pluck('supplier');//get array of suppliers id $suppliers = (new Collection($repairs))->unique();//get unique collect ... -
每个班次都有一个hasMany ,因此你不能在集合上调用shift_workers() 。 你要循环,如下所示: foreach ($event->shifts as $shift) { $shift->shift_workers()->saveMany($workers); } Each shift has a hasMany, so you can't call shift_workers() on a collection. You've to loop, like below: forea ...
-
在Eloquent文档中,您可以看到调用find方法从生成的查询中获取所有列。 因此,在您的情况下,您有两个表连接contacts和users和用户表id覆盖联系人id 。 要仅获取联系人字段,只需在find方法中指定所需的列,如下所示: $contact = $this->organization->contact()->find(Input::get('id'), ['contacts.*']); 然后你将只加载联系人数据, id将是正确的:) From the Eloquent documentat ...