chiark / gitweb /
catch a vector-size mismatch in C++
authorstevenj <stevenj@alum.mit.edu>
Mon, 5 Apr 2010 07:28:11 +0000 (03:28 -0400)
committerstevenj <stevenj@alum.mit.edu>
Mon, 5 Apr 2010 07:28:11 +0000 (03:28 -0400)
darcs-hash:20100405072811-c8de0-307c0f8c22e707816cbe2da178b2ff92fc6a596f.gz

api/nlopt-in.hpp

index a4d91440ed5d7b3a979168c92dfacc2f0defd1b5..cc09c44ee9010a488210f610c8b60966a7d551cb 100644 (file)
@@ -109,6 +109,8 @@ namespace nlopt {
       return result(ret);
     }
     result optimize(std::vector<double> &x, double &opt_f) {
+      if (o && nlopt_get_dimension(o) != x.size())
+        throw std::invalid_argument("dimension mismatch");
       return optimize(x.empty() ? NULL : &x[0], opt_f);
     }