@@ -329,6 +329,52 @@ namespace mapper {
329329 mpr_time _time;
330330 };
331331
332+ template <class T >
333+ class ListIter {
334+ public:
335+ ListIter (mpr_list list) {
336+ _list = list;
337+ }
338+
339+ T operator *()
340+ { return _list ? T (*_list) : T (NULL ); }
341+ operator T ()
342+ { return _list ? T (*_list) : T (NULL ); }
343+
344+ operator mpr_list () const {
345+ return _list;
346+ }
347+
348+ ListIter operator ++(int ) {
349+ if (_list != nullptr ) {
350+ auto next = mpr_list_get_next (_list);
351+ if (next == nullptr ) {
352+ mpr_list_free (_list);
353+ }
354+ return ListIter (next);
355+ } else {
356+ return ListIter ((mpr_list)nullptr );
357+ }
358+ }
359+
360+ ListIter& operator ++() {
361+ if (_list != nullptr ) {
362+ auto next = mpr_list_get_next (_list);
363+ if (next == nullptr ) {
364+ mpr_list_free (next);
365+ }
366+ _list = next;
367+ }
368+ return *this ;
369+ }
370+
371+ bool operator ==(const ListIter& rhs) const
372+ { return (_list == rhs._list ); }
373+
374+ private:
375+ mpr_list _list;
376+ };
377+
332378 /* ! List objects provide a lazily-computed iterable list of results
333379 * from running queries against a mapper::Graph. */
334380 template <class T >
@@ -340,49 +386,30 @@ namespace mapper {
340386 using difference_type = int ;
341387 using pointer = int *;
342388 using reference = int &;
389+ using iter = ListIter<T>;
343390
344391 /* Copy constructor */
345392 List (const List& orig)
346- : List(mpr_list_get_cpy(orig._list)) {}
347-
348- friend void swap (List& first, List& second)
349- {
350- using std::swap;
351- swap (first._list , second._list );
352- }
353-
354- /* Copy assignment operator */
355- List& operator =(List orig) noexcept
356- {
357- swap (*this , orig);
358- return *this ;
359- }
393+ { _list = mpr_list_get_cpy (orig._list ); }
360394
361395 /* Move constructor */
362396 List (List&& orig) noexcept
363397 { _list = orig._list ; orig._list = NULL ; }
364398
365- /* Move assignment operator */
366- List& operator =(List&& orig) noexcept
367- { std::swap (_list, orig._list ); return *this ; }
368-
369399 ~List ()
370- { mpr_list_free (_list); }
400+ { if (_list == nullptr ) { return ;} mpr_list_free (_list); }
371401
372402 operator mpr_list () { return _list; }
373403
374404 bool operator ==(const List& rhs)
375405 { return (0 == mpr_list_cmp (_list, rhs._list )); }
376406 bool operator !=(const List& rhs)
377407 { return (0 != mpr_list_cmp (_list, rhs._list )); }
378- List& operator ++()
379- { if (_list) _list = mpr_list_get_next (_list); RETURN_SELF ; }
380- List operator ++(int )
381- { List tmp (*this ); operator ++(); return tmp; }
382- List& begin ()
383- { RETURN_SELF ; }
384- List end ()
385- { return List (0 ); }
408+
409+ iter begin ()
410+ { return ListIter<T>(_list); }
411+ iter end ()
412+ { return ListIter<T>((mpr_list)nullptr ); }
386413
387414 /* ! Return the number of items in a List
388415 * \return The number of items in this list. */
@@ -1903,7 +1930,7 @@ namespace mapper {
19031930 std::string iface () const
19041931 {
19051932 const char *iface = mpr_graph_get_interface (_obj);
1906- return iface ? std::string (iface) : std::string ( );
1933+ return std::string (iface);
19071934 }
19081935
19091936 /* ! Specify the multicast group and port to use.
0 commit comments