From ed17172ea74a8beaaaf5f2494bd1fecc81ff6144 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 2 Nov 2011 11:04:55 +0200 Subject: Add result_iterator::id() function that returns id without loading object --- doc/manual.xhtml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'doc') diff --git a/doc/manual.xhtml b/doc/manual.xhtml index 690c17f..d262319 100644 --- a/doc/manual.xhtml +++ b/doc/manual.xhtml @@ -3837,6 +3837,9 @@ namespace odb void load (T& x); + + typename object_traits<T>::id_type + id (); }; } @@ -3905,6 +3908,25 @@ namespace odb } +

The id() function return the object id of the current + object. While we can achieve the same by loading the object and getting + its id, this function is more efficient since it doesn't actually + create the object. This can be useful when all we need is the object's + identifier. For example:

+ +
+  std::set<unsigned long> set = ...; // Persons of interest.
+
+  result r (db.query<person> (query::first == "John"));
+
+  for (result::iterator i (r.begin ()); i != r.end (); ++i)
+  {
+    if (set.find (i.id ()) != set.end ()) // No object loaded.
+    {
+      cout << i->first () << endl; // Object loaded.
+    }
+  }
+  
-- cgit v1.1