相关疑难解决方法(0)

带有容器和默认分配器的模板模板参数:我可以使我的声明更紧凑吗?

我正在看这个有趣的主题:https: //stackoverflow.com/a/16596463/2436175

我的具体情况涉及使用来自opencv的cv :: Point_和cv :: Rect_的std容器声明模板化函数.我想反对模板:

  • 我将使用的std容器的类型
  • 完成cv :: Point_和cv :: Rect_定义的基本数据类型

我最后得到了以下声明:

template <typename T, template <typename, typename> class Container_t>
    void CreateRects(const Container_t<cv::Point_<T>,std::allocator<cv::Point_<T> > >& points,
                     const T value,
                     Container_t<cv::Rect_<T>,std::allocator<cv::Rect_<T> > >& rects) {

    }
Run Code Online (Sandbox Code Playgroud)

用这个编译很好:

void dummy() {

const std::vector<cv::Point_<double> > points;
std::vector<cv::Rect_<double> > rects;
CreateRects(points,5.0,rects);

}
Run Code Online (Sandbox Code Playgroud)

(我也看到我也可以使用,例如,CreateRects<double>(points,5,rects))

我想知道是否存在任何方式使我的声明更紧凑,例如,无需指定默认分配器的2倍.

c++ templates opencv

7
推荐指数
1
解决办法
983
查看次数

标签 统计

c++ ×1

opencv ×1

templates ×1