Merge pull request #247 from aldanor/iterators

Use prefix increment in make_iterator
diff --git a/include/pybind11/common.h b/include/pybind11/common.h
index 560be43..daafa7d 100644
--- a/include/pybind11/common.h
+++ b/include/pybind11/common.h
@@ -116,7 +116,7 @@
 extern "C" {
     struct _Py_atomic_address { void *value; };
     PyAPI_DATA(_Py_atomic_address) _PyThreadState_Current;
-};
+}
 #endif
 
 #define PYBIND11_TRY_NEXT_OVERLOAD ((PyObject *) 1) // special failure return code
diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h
index 1438e34..d472531 100644
--- a/include/pybind11/pybind11.h
+++ b/include/pybind11/pybind11.h
@@ -1028,7 +1028,10 @@
     (void) wr.release();
 }
 
-template <typename Iterator> struct iterator_state { Iterator it, end; };
+template <typename Iterator> struct iterator_state {
+    Iterator it, end;
+    bool first;
+};
 
 NAMESPACE_END(detail)
 
@@ -1044,13 +1047,17 @@
         class_<state>(handle(), "")
             .def("__iter__", [](state &s) -> state& { return s; })
             .def("__next__", [](state &s) -> ValueType {
+                if (!s.first)
+                    ++s.it;
+                else
+                    s.first = false;
                 if (s.it == s.end)
                     throw stop_iteration();
-                return *s.it++;
+                return *s.it;
             }, return_value_policy::reference_internal, std::forward<Extra>(extra)...);
     }
 
-    return (iterator) cast(state { first, last });
+    return (iterator) cast(state { first, last, true });
 }
 
 template <typename Type, typename... Extra> iterator make_iterator(Type &value, Extra&&... extra) {