lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master d0714fd 1/2: Prefer lambdas to std::bind()


From: Greg Chicares
Subject: [lmi-commits] [lmi] master d0714fd 1/2: Prefer lambdas to std::bind()
Date: Tue, 6 Nov 2018 05:37:23 -0500 (EST)

branch: master
commit d0714fdbcd019e8b2b15dab3ceffbe28d2b74099
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Prefer lambdas to std::bind()
---
 input_test.cpp | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/input_test.cpp b/input_test.cpp
index a85a47c..c65da42 100644
--- a/input_test.cpp
+++ b/input_test.cpp
@@ -150,18 +150,16 @@ void input_test::test_product_database()
         ,"Assertion '1 == v.extent()' failed."
         );
 
-    // Use bind<R> where compilation errors would occur without <R>.
-    // The "recommended" solution forces the "right" overload by
-    // writing an explicit pointer to member:
-    //   http://lists.boost.org/boost-users/2007/06/28832.php
-    // but if that becomes necessary, then bind should be abandoned:
-    // writing individual functions by hand is simpler and clearer.
+    auto f0 = [&db]     {db.initialize("sample");};
+    auto f1 = [&db, &v] {db.Query(v, DB_MaturityAge);};
+    auto f2 = [&db]     {db.Query(DB_MaturityAge);};
+    auto f3 = [&db]     {db.entity_from_key(DB_MaturityAge);};
     std::cout
         << "\n  Database speed tests..."
-        << "\n  initialize()      : " << 
TimeAnAliquot(std::bind(&product_database::initialize,      &db, "sample"       
  ))
-        << "\n  Query(vector)     : " << TimeAnAliquot(std::bind((void 
(product_database::*)(std::vector<double>&, e_database_key) 
const)&product_database::Query,           &db, v, DB_MaturityAge))
-        << "\n  Query(scalar)     : " << TimeAnAliquot(std::bind((double 
(product_database::*)(e_database_key) const)&product_database::Query,           
&db,    DB_MaturityAge))
-        << "\n  entity_from_key() : " << 
TimeAnAliquot(std::bind(&product_database::entity_from_key, &db,    
DB_MaturityAge))
+        << "\n  initialize()      : " << TimeAnAliquot(f0)
+        << "\n  Query(vector)     : " << TimeAnAliquot(f1)
+        << "\n  Query(scalar)     : " << TimeAnAliquot(f2)
+        << "\n  entity_from_key() : " << TimeAnAliquot(f3)
         << '\n'
         ;
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]