I have a basic API that passes const char * and length:
foo(const char* data, const uint32_t len);
I would like to wrap this data / length in a light weight container that can be repeated and has the ability to randomly access but not make a copy (like a vector, for example). What is the best way to achieve this? Const char * data is not necessarily a string; it can contain NULL everywhere.
I use STL and Boost. I saw boost :: as_array <> and as_literal <> - is one of the following here?
. - :
template <class T> class array_ref { public: // makes it work with iterator traits.. typedef T value_type; typedef size_t size_type; typedef ptrdiff_t difference_type; typedef T* pointer; typedef T* iterator; typedef T& reference; typedef const T* const_pointer; typedef const T* const_iterator; typedef const T& const_reference; public: array_ref(T *p, size_t n) : data_(p), len_(n) {} // iteration iterator begin() { return data_; } iterator end() { return data_ + len_; } const_iterator begin() const { return data_; } const_iterator end() const { return data_ + len_; } // access reference operator[](size_t n) { return data_[n]; } reference at(size_t n) { return data_[n]; } const_reference operator[](size_t n) const { return data_[n]; } const_reference at(size_t n) const { return data_[n]; } // capacity size_t size() const { return len_; } bool empty() const { return size() == 0; } // raw access T* data() const { return data_; } // etc... private: T* data_; size_t len_; };
, . , , . .
, . , , , .
iterator_facade http://www.boost.org/doc/libs/1_43_0/libs/iterator/doc/iterator_facade.html iterator_range
iterator_range , http://www.boost.org/doc/libs/1_42_0/libs/range/doc/utility_class.html#iter_range
boost::iterator_range<char*> range(begin, begin + N);
iterator_facade
, as_array / as_literal , . , , , , (, , , , , ).
: , , , - , , . comp.lang.++ / comp.lang.++. , , 12 15 , , , ( , , Google ). , - ( ). , , , , (?) as-is - ++ .
Source: https://habr.com/ru/post/1754733/More articles:How to make labels with properties in Django? - django-tagginghttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1754729/will-a-page-taking-2-3-mins-to-render-cause-a-javascript-taking-too-long-warning&usg=ALkJrhhmameN_8ifzeec4EACC-CskmMklQHTML image scaling - htmlhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1754731/organizing-django-tagging-tags-or-assigning-properties-to-tags&usg=ALkJrhgq3yimcKfluXFHPZCFFffF4tqYPgPlay AVI files in OpenCV - c ++objc: avoid method method name conflicts? - objective-cWhy doesn't jQuery datapicker limit input when setting date format? - jquery-uiDownload the torrent form torcache.com using php.? - pythonBlock characters from input text field, enter mirror in span or div - javascriptC # .NET: how to pause and resume a program when a key is pressed? - c #All Articles