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

open
None
1
2014-07-28
2014-07-27
Dov Grobgeld
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

    • assigned_to: Mathieu Malaterre
    • Priority: 5 --> 1
     
  • #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.