Menu

#31 Support C++11 range based for loop for gdcm::DataSet

open
None
1
2014-07-28
2014-07-27
No

By adding STL iterator api functions begin() and end() to gdm::DataSet, range for statements may be used for looping over its elements. This will allow using the following equivalent syntaxes:

// Current syntax
for (auto it=ds.Begin(); it!= ds.End(); ++it) {
    const auto& el = *it;
    // do something with el
}
// equivalent shorthand dependeding on ds.begin() and ds.end()
for (const auto& el: ds)
    // do something with el

See e.g.: http://www.stroustrup.com/C++11FAQ.html#for

Discussion

  • Mathieu Malaterre

    • assigned_to: Mathieu Malaterre
    • Priority: 5 --> 1
     
  • Mathieu Malaterre

    #define Begin begin
    #define End end
    #include "gdcmDataSet.h"
    [...]
    #undef begin
    #undef end
    

    cheers

     

    Last edit: Mathieu Malaterre 2014-07-28
  • Dov Grobgeld

    Dov Grobgeld - 2014-07-28

    That's a nice hack, but it would be even prettier not to have to do it.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.