私はコードが含まれている、this answerを掲載している:ラムダ識別子はどのようにキャプチャされますか?
[first = index == 0U ? polygon.back() : polygon[index - 1U],
second = polygon[index],
third = index == size(polygon) - 1U ? polygon.front() : polygon[index + 1U]](auto& output){ output.push_back(first);
output.push_back(second);
output.push_back(third); };
しかし、私は唯一の希望:私はfirst
、second
、およびthird
は本当にこのようなラムダ識別子として使用することができると考えていた
template <typename T>
auto vertex_triangle(const size_t index, const vector<pair<T, T>>& polygon) {
const auto& first = index == 0U ? polygon.back() : polygon[index - 1U];
const auto& second = polygon[index];
const auto& third = index == size(polygon) - 1U ? polygon.front() : polygon[index + 1U];
return [&](auto& output){ output.push_back(first);
output.push_back(second);
output.push_back(third); };
}
一定の基準で取り込む。識別子に型を指定することなく、これをどのように行うことができますか?
ラムダの各インスタンスは、固有の名前のないクラスのインスタンスです。あなたはラムダ、またはそのようなものに "識別子"を割り当てることはできません。 –
@Sam。私はラムダがファーストクラスのタイプであるとは反対します。そして、これは最初の質問とは関係ありません。 –
あなたは疑問に思うのですが、constの値による取り込みを避けるために、const参照を取り込む方法は?ところで、そのコードの最後はひどく読めません。私はそれがこの場合には価値があるとは思わない。 – StoryTeller