[Range] Creating a range for a scoped_array (with known length)
Hi, I have a scoped_array with some chars inside (so a boost::scoped_array<char>). I want to use the string algorithms, but I can't managed to get a range from the scoped_array. I don't know if the data ends with a '\0' (it's received from asio with a read()), so I can't rely on as_literal. Is there a way of creating a Range directly with two iterators? Matthieu -- Information System Engineer, Ph.D. Blog: http://matt.eifelle.com LinkedIn: http://www.linkedin.com/in/matthieubrucher
Den 03-11-2010 14:56, Matthieu Brucher skrev:
Hi,
I have a scoped_array with some chars inside (so a boost::scoped_array<char>). I want to use the string algorithms, but I can't managed to get a range from the scoped_array. I don't know if the data ends with a '\0' (it's received from asio with a read()), so I can't rely on as_literal.
Is there a way of creating a Range directly with two iterators?
boost::make_iterator_range( <begin>, <end> ) ? -Thorsten
2010/11/3 Thorsten Ottosen <nesotto@cs.aau.dk>:
Den 03-11-2010 14:56, Matthieu Brucher skrev:
Hi,
I have a scoped_array with some chars inside (so a boost::scoped_array<char>). I want to use the string algorithms, but I can't managed to get a range from the scoped_array. I don't know if the data ends with a '\0' (it's received from asio with a read()), so I can't rely on as_literal.
Is there a way of creating a Range directly with two iterators?
boost::make_iterator_range( <begin>, <end> )
Hi, Indeed, it is as simple as this. The issue I also faced is that the string algorithms expect a reference to an iterator, so I had to build it before, and not use a temporary. Thanks, Matthieu -- Information System Engineer, Ph.D. Blog: http://matt.eifelle.com LinkedIn: http://www.linkedin.com/in/matthieubrucher
On Wed, Nov 3, 2010 at 1:56 PM, Matthieu Brucher <matthieu.brucher@gmail.com
wrote:
Hi,
I have a scoped_array with some chars inside (so a boost::scoped_array<char>). I want to use the string algorithms, but I can't managed to get a range from the scoped_array. I don't know if the data ends with a '\0' (it's received from asio with a read()), so I can't rely on as_literal.
AFAICT boost::scoped_array only stores the array as a pointer, hence the size information is lost and it is not possible to obtain the end of the conceptual range from this class alone. boost::scoped_array is primarily intended to work in a similar fashion to boost::scoped_ptr but for allocations that require a corresponding delete[]. Perhaps consider boost::array, std::string, or std::vector instead?
Is there a way of creating a Range directly with two iterators?
Yes, there is - boost::make_iterator_range(first, last)
Matthieu -- Information System Engineer, Ph.D. Blog: http://matt.eifelle.com LinkedIn: http://www.linkedin.com/in/matthieubrucher _______________________________________________
Regards, Neil Groves
2010/11/3 Neil Groves <neil@grovescomputing.com>:
On Wed, Nov 3, 2010 at 1:56 PM, Matthieu Brucher <matthieu.brucher@gmail.com> wrote:
Hi,
I have a scoped_array with some chars inside (so a boost::scoped_array<char>). I want to use the string algorithms, but I can't managed to get a range from the scoped_array. I don't know if the data ends with a '\0' (it's received from asio with a read()), so I can't rely on as_literal.
AFAICT boost::scoped_array only stores the array as a pointer, hence the size information is lost and it is not possible to obtain the end of the conceptual range from this class alone. boost::scoped_array is primarily intended to work in a similar fashion to boost::scoped_ptr but for allocations that require a corresponding delete[].
Perhaps consider boost::array, std::string, or std::vector instead?
This is not an issue for me. I have the size of the data with me. I can't use boost::array, std::string or std::vector because the data may be processed by various optimized algorithms, and I don't want to pass pointers to those functions, and not a compelx container either (for performance purposes).
Is there a way of creating a Range directly with two iterators?
Yes, there is - boost::make_iterator_range(first, last)
I think this might be lacking in the examples. Generally, they are based on fully-fledged containers, not iterators. Matthieu -- Information System Engineer, Ph.D. Blog: http://matt.eifelle.com LinkedIn: http://www.linkedin.com/in/matthieubrucher
participants (3)
-
Matthieu Brucher
-
Neil Groves
-
Thorsten Ottosen