C++ c++;lambda已使用但未初始化

C++ c++;lambda已使用但未初始化,c++,klocwork,C++,Klocwork,这是我的代码,我得到了klocworks错误 “值”在此函数中未初始化使用 /// Converts rgb to grayscale (in all channels) template <typename T> void convert_to_grayscale(rgb_image_s<T> &img) { auto r = img[rgb_color_e::red]; auto g = img[rgb_color_e::green];

这是我的代码,我得到了klocworks错误 “值”在此函数中未初始化使用

/// Converts rgb to grayscale (in all channels)
template <typename T>
void convert_to_grayscale(rgb_image_s<T> &img)
{
    auto r = img[rgb_color_e::red];
    auto g = img[rgb_color_e::green];
    auto b = img[rgb_color_e::blue];
    r.foreach([](T &r, T &g, T &b)
    {
        /// error: 'value' is used uninitialized in this function.
        auto value = reduce_to<T>(0.299 * r + 0.587 * g + 0.114 * b);
        r = value;
        g = value;
        b = value;
    }, g, b);
}
///将rgb转换为灰度(在所有通道中)
模板
无效转换为灰度(rgb图像和图像)
{
自动r=img[rgb_颜色:红色];
auto g=img[rgb_color_e::green];
自动b=img[rgb_color_e::blue];
r、 foreach([](T&r、T&g、T&b)
{
///错误:“值”在此函数中未初始化使用。
自动值=将_减至(0.299*r+0.587*g+0.114*b);
r=数值;
g=数值;
b=数值;
},g,b);
}
使功能化

 // For integral types T only
    template<typename T>  // T <- T do nothing
    typename std::enable_if<std::is_integral<T>::value, T>::type reduce_to(T t) { return t; }
//仅适用于整型T

template//T这是klocwork中的一个bug。@formerlyknownas\u 463035818您在r上迭代。@formerlyknownas\u 463035818它在
foreach()前面。
。(我也困惑了一会儿,直到找到了它。);-)
 template <class func, typename... types> func&
            foreach(func &&f, types&&... images) const
        {
            // Check that the other input images are at least same size as this is
            validate_sizes(images.size()...);

            auto skipx = std::initializer_list<int>({ _skip_x, images._skip_x... });
            auto all_ones = std::all_of(skipx.begin(), skipx.end(), [](const int skip) { return skip == 1; });
            if (all_ones)
            {
                for (auto y : _height)
                {
                    iterate_row(_width, f, &at(y, 0), &images.at(y, 0)...);
                }
            }
            else
            {
                for (auto y : _height)
                {
                    iterate_row(_width, f, make_row_iterator(y), images.make_row_iterator(y)...);
                }
            }
            return f;
        }
   /// Converts rgb to grayscale (in all channels)
    template <typename T>
    void convert_to_grayscale(rgb_image_s<T> &img)
    {
        auto r = img[rgb_color_e::red];
        auto g = img[rgb_color_e::green];
        auto b = img[rgb_color_e::blue];
        r.foreach([](T &r, T &g, T &b)
        {
            T value = reduce_to<T>(0.299 * r + 0.587 * g + 0.114 * b); // changed to T instead of auto
            r = value;
            g = value;
            b = value;
        }, g, b);
    }