title: Visual Studio 2015 error C4996 'std::_Copy_impl': Function call with parameters that may be unsafe
body: <p>I wrote this template class:</p>
  
  <p>.hpp:</p>
  
  <pre><code>#ifndef BIVARIATEGAUSSIANPDF_LIB_H
  #define BIVARIATEGAUSSIANPDF_LIB_H
  
  #if defined BIVARIATEGAUSSIANPDF_LIB_EXPORTS
  #define BIVARIATEGAUSSIANPDFDLL_API __declspec(dllexport)
  #else
  #define BIVARIATEGAUSSIANPDFDLL_API __declspec(dllimport)
  #endif
  
  #include &lt;vector&gt;
  #include &lt;opencv2\core\core.hpp&gt;
  
  namespace cv
  {
      class Mat;
  }
  
  #define _USE_MATH_DEFINES
  #include &lt;math.h&gt;
  
  template&lt;class T, class N&gt;
  class BivariateGaussianPDF
  {
  public:
      BIVARIATEGAUSSIANPDFDLL_API BivariateGaussianPDF(const std::vector&lt;T&gt; &amp; i_v1,
                                                       const std::vector&lt;N&gt; &amp; i_v2);
  
      BIVARIATEGAUSSIANPDFDLL_API ~BivariateGaussianPDF();
  
      BIVARIATEGAUSSIANPDFDLL_API void compute();
  
      BIVARIATEGAUSSIANPDFDLL_API inline std::vector&lt;double&gt; getPDF() const { return m_pdf; }
  
  private:
      cv::Mat m_matrix;
      std::vector&lt;double&gt; m_pdf;
  };
  
  template class BivariateGaussianPDF&lt;int, int&gt;;
  template class BivariateGaussianPDF&lt;int, float&gt;;
  template class BivariateGaussianPDF&lt;int, double&gt;;
  template class BivariateGaussianPDF&lt;float, int&gt;;
  template class BivariateGaussianPDF&lt;float, float&gt;;
  template class BivariateGaussianPDF&lt;float, double&gt;;
  template class BivariateGaussianPDF&lt;double, int&gt;;
  template class BivariateGaussianPDF&lt;double, float&gt;;
  template class BivariateGaussianPDF&lt;double, double&gt;;
  
  #endif
  </code></pre>
  
  <p>and .cpp:</p>
  
  <pre><code>#include "stdafx.h"
  #include "bivariateGaussianPDF_lib.h"
  #include &lt;iterator&gt;
  
  template&lt;class T, class N&gt;
  BivariateGaussianPDF&lt;T, N&gt;::BivariateGaussianPDF(const std::vector&lt;T&gt;&amp; i_v1,
                                                   const std::vector&lt;N&gt;&amp; i_v2)
      :m_pdf(i_v1.size())
  {
      std::vector&lt;double&gt; temp_v1(std::begin(i_v1), std::end(i_v1));
      std::vector&lt;double&gt; temp_v2(std::begin(i_v2), std::end(i_v2));
      m_matrix.create(2, i_v1.size(), CV_64F);
      double * r0_ptr = m_matrix.ptr&lt;double&gt;(0);
      double * r1_ptr = m_matrix.ptr&lt;double&gt;(1);
      std::copy(temp_v1.begin(), temp_v1.end(), r0_ptr);
      std::copy(temp_v2.begin(), temp_v2.end(), r1_ptr);
  }
  
  template&lt;class T, class N&gt;
  BivariateGaussianPDF&lt;T, N&gt;::~BivariateGaussianPDF()
  {
      m_matrix.release();
  }
  
  template&lt;class T, class N&gt;
  void BivariateGaussianPDF&lt;T, N&gt;::compute()
  {
      cv::Mat row_mean, cov, inverseCov, temp_pdf;
  
      // compute covariance matrix
      cv::calcCovarMatrix(m_matrix, cov, row_mean, CV_COVAR_ROWS | CV_COVAR_NORMAL);
      // scale covariance matrix
      cov = cov / (m_matrix.cols - 1);
      // inverse of covariance matrix
      inverseCov = cov.inv();
  
      // determinant of covariance matrix
      const double det = cv::determinant(cov);
  
      // X = [x1; x2 ... ; xN] --&gt; [x1 - mu1; x2 - mu2; ... ; xN - muN ]
      cv::subtract(m_matrix.row(0), row_mean.row(0), m_matrix.row(0));
      cv::subtract(m_matrix.row(1), row_mean.row(1), m_matrix.row(1));
  
      // (inv*X).*X
      cv::reduce((inverseCov*m_matrix).mul(m_matrix), temp_pdf, 0, CV_REDUCE_SUM);
      temp_pdf = -0.5*temp_pdf;
      cv::exp(temp_pdf, temp_pdf);
  
      // bivariate gaussian pdf
      temp_pdf = (0.5 / (M_PI*std::sqrt(det)))*temp_pdf;
  
      const double * d_ptr = temp_pdf.ptr&lt;double&gt;(0);
      std::copy(d_ptr, d_ptr + temp_pdf.cols, m_pdf.begin());
  }
  </code></pre>
  
  <p>When I compile I get this message:</p>
  
  <blockquote>
    <p>Error C4996   'std::_Copy_impl': Function call with parameters that may
    be unsafe - this call relies on the caller to check that the passed
    values are correct. To disable this warning, use
    -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators' bivariateGaussianPDF_lib    c:\program files
    (x86)\microsoft visual studio 14.0\vc\include\xutility    2229</p>
  </blockquote>
  
  <p>Reading <a href="https://stackoverflow.com/questions/19079482/error-c4996-std-copy-impl-function-call-with-parameters-that-may-be-unsafe">this answer</a> I understood because I get the error (I'm not calling std::copy according to msdn function signature) but I don't know how to fix it. I think the error lines are:</p>
  
  <pre><code>std::copy(temp_v1.begin(), temp_v1.end(), r0_ptr);
  std::copy(temp_v2.begin(), temp_v2.end(), r1_ptr);
  </code></pre>
  
  <p>Any help is appreciated.</p>