hideakitai/ArxContainer

build errors on Due

Closed this issue · 3 comments

Surprisingly enough Due really dislikes the const styling of begin.

C:\Users\name\Documents\Arduino\libraries\ArxContainer/ArxContainer.h:659:47: error: passing 'arx::RingBuffer<arx::pair<long unsigned int, HydroponicsCalibrationData*>, 8u>::const_iterator {aka const arx::RingBuffer<arx::pair<long unsigned int, HydroponicsCalibrationData*>, 8u>::Iterator}' as 'this' argument of 'arx::RingBuffer<T, N>::Iterator arx::RingBuffer<T, N>::Iterator::operator+(int) [with T = arx::pair<long unsigned int, HydroponicsCalibrationData*>; unsigned int N = 8u]' discards qualifiers [-fpermissive] const_iterator it = this->begin() + i;

Think I solved it by making the Iterator operator+(const int n) member method down in RingBuffer a const member method, i.e.

Iterator operator+(const int n) const {

I think the source of this problem is that ArxContainer defines iterator as a class and not pointer to a value, so this definition:

using const_iterator = const Iterator;

creates "a const pointer to a value" instead of "a pointer to a const value", which would be the correct one.

This piece of my code:

typedef arx::array<float, 3> arr_t;

void print_arr2(const arr_t& arr) {
  for (arr_t::const_iterator i = arr.begin(); i != arr.end(); ++i) {
    ...
  }
}

gives me the similar warning:

C:\Arduino\libraries\ArxContainer\examples\array_copy_constructor_test\array_copy_constructor_test.ino: In function 'void print_arr2(const arr_t&)':
C:\Arduino\libraries\ArxContainer\examples\array_copy_constructor_test\array_copy_constructor_test.ino:17:65: warning: passing 'arx::array<float, 3>::const_iterator {aka const arx::RingBuffer<float, 3>::Iterator}' as 'this' argument discards qualifiers [-fpermissive]
   for (arr_t::const_iterator i = arr.begin(); i != arr.end(); ++i) {
                                                                 ^
In file included from C:\Arduino\libraries\ArxContainer\examples\array_copy_constructor_test\array_copy_constructor_test.ino:1:0:
c:\Arduino\libraries\ArxContainer/ArxContainer.h:133:19: note:   in call to 'arx::RingBuffer<T, N>::Iterator& arx::RingBuffer<T, N>::Iterator::operator++() [with T = float; unsigned int N = 3]'
         Iterator& operator++() {
                   ^~~~~~~~

This is because I have called non-const method operator++() on const-defined iterator class.

I'll try to fix it somehow, but I think it wouldn't be a small patch. Or maybe I see it wrong?

Fixd by #6