Remove uses of std::iterator (deprecated in C++17)

Detailed reasoning for the deprecation is provided by the paper proposing deprecation (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0174r2.html) and a related LWG issue (https://cplusplus.github.io/LWG/issue2438).

This was the only issue preventing a clean compile with VS 15.7.2 with c++17/c++latest set as the target language

The issue could be resolved in two ways. Providing a custom replacement to std::iterator (a very simple structure) or by providing the 5 required typedefs. The only functional difference from my reading is that the typedefs are not immediately available to the implementer with the inheritance. I find the inline typedefs to be clearer hence the selection in this commit
This commit is contained in:
Joshua 2018-05-30 07:52:54 +12:00 committed by Crzyrndm
parent e350a7734d
commit e9071432e1
3 changed files with 61 additions and 42 deletions

View File

@ -37,18 +37,22 @@ class worksheet;
// because one needs to point at a const workbook and the other needs
// to point at a non-const workbook stored as a member variable, respectively.
/// <summary>
/// Alias the parent class of this iterator to increase clarity.
/// </summary>
using ws_iter_type = std::iterator<std::bidirectional_iterator_tag,
worksheet, std::ptrdiff_t, worksheet *, worksheet>;
/// <summary>
/// An iterator which is used to iterate over the worksheets in a workbook.
/// </summary>
class XLNT_API worksheet_iterator : public ws_iter_type
class XLNT_API worksheet_iterator
{
public:
/// <summary>
/// iterator tags required for use with standard algorithms and adapters
/// </summary>
using iterator_category = std::bidirectional_iterator_tag;
using value_type = worksheet;
using difference_type = std::ptrdiff_t;
using pointer = worksheet *;
using reference = worksheet; // intentionally value
/// <summary>
/// Constructs a worksheet iterator from a workbook and sheet index.
/// </summary>
@ -106,18 +110,21 @@ private:
};
/// <summary>
/// Alias the parent class of this iterator to increase clarity.
/// </summary>
using c_ws_iter_type = std::iterator<std::bidirectional_iterator_tag,
const worksheet, std::ptrdiff_t, const worksheet *, const worksheet>;
/// <summary>
/// An iterator which is used to iterate over the worksheets in a const workbook.
/// </summary>
class XLNT_API const_worksheet_iterator : public c_ws_iter_type
class XLNT_API const_worksheet_iterator
{
public:
/// <summary>
/// iterator tags required for use with standard algorithms and adapters
/// </summary>
using iterator_category = std::bidirectional_iterator_tag;
using value_type = const worksheet;
using difference_type = std::ptrdiff_t;
using pointer = const worksheet *;
using reference = const worksheet; // intentionally value
/// <summary>
/// Constructs a worksheet iterator from a workbook and sheet index.
/// </summary>

View File

@ -40,18 +40,21 @@ class cell;
class cell_reference;
class range_reference;
/// <summary>
/// Alias the parent class of this iterator to increase clarity.
/// </summary>
using c_iter_type = std::iterator<std::bidirectional_iterator_tag,
cell, std::ptrdiff_t, cell *, cell>;
/// <summary>
/// A cell iterator iterates over a 1D range by row or by column.
/// </summary>
class XLNT_API cell_iterator : public c_iter_type
class XLNT_API cell_iterator
{
public:
/// <summary>
/// iterator tags required for use with standard algorithms and adapters
/// </summary>
using iterator_category = std::bidirectional_iterator_tag;
using value_type = cell;
using difference_type = std::ptrdiff_t;
using pointer = cell *;
using reference = cell; // intentionally value
/// <summary>
/// Constructs a cell_iterator from a worksheet, range, and iteration settings.
/// </summary>
@ -135,7 +138,7 @@ private:
/// If true, cells that don't exist in the worksheet will be skipped during iteration.
/// </summary>
bool skip_null_;
/// <summary>
/// If true, when on the last column, the cursor will continue to the next row
/// (and vice versa when iterating in column-major order) until reaching the
@ -144,18 +147,21 @@ private:
bool wrap_;
};
/// <summary>
/// Alias the parent class of this iterator to increase clarity.
/// </summary>
using cc_iter_type = std::iterator<std::bidirectional_iterator_tag,
const cell, std::ptrdiff_t, const cell *, const cell>;
/// <summary>
/// A cell iterator iterates over a 1D range by row or by column.
/// </summary>
class XLNT_API const_cell_iterator : public cc_iter_type
class XLNT_API const_cell_iterator
{
public:
/// <summary>
/// iterator tags required for use with standard algorithms and adapters
/// </summary>
using iterator_category = std::bidirectional_iterator_tag;
using value_type = const cell;
using difference_type = std::ptrdiff_t;
using pointer = const cell *;
using reference = const cell; // intentionally value
/// <summary>
/// Constructs a cell_iterator from a worksheet, range, and iteration settings.
/// </summary>

View File

@ -35,19 +35,22 @@ namespace xlnt {
class cell_vector;
/// <summary>
/// Alias the parent class of this iterator to increase clarity.
/// </summary>
using r_iter_type = std::iterator<std::bidirectional_iterator_tag,
cell_vector, std::ptrdiff_t, cell_vector *, cell_vector>;
/// <summary>
/// An iterator used by worksheet and range for traversing
/// a 2D grid of cells by row/column then across that row/column.
/// </summary>
class XLNT_API range_iterator : public r_iter_type
class XLNT_API range_iterator
{
public:
/// <summary>
/// iterator tags required for use with standard algorithms and adapters
/// </summary>
using iterator_category = std::bidirectional_iterator_tag;
using value_type = cell_vector;
using difference_type = std::ptrdiff_t;
using pointer = cell_vector *;
using reference = cell_vector; // intentionally value
/// <summary>
/// Constructs a range iterator on a worksheet, cell pointing to the current
/// row or column, range bounds, an order, and whether or not to skip null column/rows.
@ -127,19 +130,22 @@ private:
bool skip_null_;
};
/// <summary>
/// Alias the parent class of this iterator to increase clarity.
/// </summary>
using cr_iter_type = std::iterator<std::bidirectional_iterator_tag,
const cell_vector, std::ptrdiff_t, const cell_vector *, const cell_vector>;
/// <summary>
/// A const version of range_iterator which does not allow modification
/// to the dereferenced cell_vector.
/// </summary>
class XLNT_API const_range_iterator : public cr_iter_type
class XLNT_API const_range_iterator
{
public:
/// <summary>
/// this iterator meets the interface requirements of bidirection_iterator
/// </summary>
using iterator_category = std::bidirectional_iterator_tag;
using value_type = const cell_vector;
using difference_type = std::ptrdiff_t;
using pointer = const cell_vector *;
using reference = const cell_vector; // intentionally value
/// <summary>
/// Constructs a range iterator on a worksheet, cell pointing to the current
/// row or column, range bounds, an order, and whether or not to skip null column/rows.