hosseinmoein / DataFrame

C++ DataFrame for statistical, Financial, and ML analysis -- in modern C++ using native types and contiguous memory storage
https://hosseinmoein.github.io/DataFrame/
BSD 3-Clause "New" or "Revised" License
2.54k stars 313 forks source link

iterator of VectorPtrView #84

Closed nehcuh closed 4 years ago

nehcuh commented 4 years ago

Hi Hosseinmoein,

Sorry to disturb again!

In your code VectorPtrView.h, you've defined iterator, const_iterator and const_reverse_iterator, each class holds an constructor like

        inline const_iterator (pointer const *node) noexcept
            : node_ (node)  {   }

However, the method of ++ operation trys to convert a const** instead of value_type*const* to iterator, is there's something wrong?

inline const_iterator operator ++ (int) noexcept  {

            value_type const  **ret_node = node_;

            node_ += 1;
            return (const_iterator (ret_node));
        }
hosseinmoein commented 4 years ago

Yeah, I don't see an issue with that. Can you show me a practical issue with an example?

nehcuh commented 4 years ago

I'm not quite sure if demo listed below is ok? I've modified from your test code vector_ptr_view_test.cc. I've added some code after instantiation of VectorPtrView which is variable vecview,

    VectorPtrView<int>::const_iterator item = vec_view.begin();
    std::cout << *item << std::endl;
    // std::cout << *(item++) << std::endl; // compilation error
    std::cout << *(++item) << std::endl;
nehcuh commented 4 years ago
error: no viable conversion from 'hmdf::VectorPtrView<int>::iterator::iter_type' (aka '__wrap_iter<int **>') to
      'hmdf::VectorPtrView<int>::iterator::value_type **' (aka 'int **')
            value_type   **ret_node = node_;
hosseinmoein commented 4 years ago

Thanks, your code snippet works fine. Do you mean this is not working

std::cout << *(item++) << std::endl;

I just pushed a fix to master

nehcuh commented 4 years ago

Got it! Thanks!