[niepce] Use lambda in geometry



commit cb6a4e1d5a428bd0af4b7c325bab650ca229b0a1
Author: Hubert Figuière <hub figuiere net>
Date:   Fri Jun 7 19:45:33 2013 -0400

    Use lambda in geometry

 src/fwk/base/geometry.cpp       |   13 +++++++------
 src/fwk/base/t/testgeometry.cpp |   25 +++++++++++++------------
 2 files changed, 20 insertions(+), 18 deletions(-)
---
diff --git a/src/fwk/base/geometry.cpp b/src/fwk/base/geometry.cpp
index fd7d576..49761f2 100644
--- a/src/fwk/base/geometry.cpp
+++ b/src/fwk/base/geometry.cpp
@@ -1,7 +1,7 @@
 /*
  * niepce - fwk/base/geometry.cpp
  *
- * Copyright (C) 2007-2008 Hubert Figuiere
+ * Copyright (C) 2007-2013 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -55,11 +55,12 @@ Rect::Rect(const std::string & s)
         throw(std::bad_cast());
     }
     int i = 0;
-    std::vector< std::string >::iterator iter;
-    for(iter = v.begin(); iter != v.end(); ++iter) {
-        _r[i] = boost::lexical_cast<int>(*iter);
-        i++;
-    }
+    for_each(v.begin(), v.end(),
+             [&i, this] (const std::string &s) {
+                 _r[i] = boost::lexical_cast<int>(s);
+                 i++;
+             }
+        );
 }
 
 Rect & Rect::scale(double _s)
diff --git a/src/fwk/base/t/testgeometry.cpp b/src/fwk/base/t/testgeometry.cpp
index 2cf946e..c386fc1 100644
--- a/src/fwk/base/t/testgeometry.cpp
+++ b/src/fwk/base/t/testgeometry.cpp
@@ -1,7 +1,7 @@
 /*
  * niepce - utils/testgeometry.cpp
  *
- * Copyright (C) 2007 Hubert Figuiere
+ * Copyright (C) 2007-2013 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -37,20 +37,21 @@ int test_main( int, char *[] )             // note the name!
        BOOST_CHECK(r2.y() == 100);
        BOOST_CHECK(r2.w() == 250);
        BOOST_CHECK(r2.h() == 250);
-       bool raised = false;
        std::vector<std::string> vtest;
        vtest.push_back("a b c d");
        vtest.push_back("100 100 150");
-       for(std::vector<std::string>::iterator iter = vtest.begin();
-               iter != vtest.end(); ++iter) {
-               try {
-                       Rect r3(*iter);
-               }
-               catch(std::bad_cast) {
-                       raised = true;
-               }
-               BOOST_CHECK(raised);
-       }
+       std::for_each(vtest.begin(), vtest.end(),
+                     [] (const std::string & s) {
+                             bool raised = false;
+                             try {
+                                     Rect r3(s);
+                             }
+                             catch(std::bad_cast) {
+                                     raised = true;
+                             }
+                             BOOST_CHECK(raised);
+                     }
+               );
 
 
     Rect dest1(0, 0, 640, 480);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]