Boost logo

Boost Users :

Subject: [Boost-users] Range - Char literal question
From: Rao, Anant (Anant.Rao_at_[hidden])
Date: 2010-10-18 16:24:45


Hi,

I need to iterate thru strings (For various reasons, I can't use string or vector<char> containers).
I found that boost::range exactly fits the bill for me. I get all the convenience of an iterator (from as_literal.hpp).

I have a piece of code

char* char_s = "I am fine";

char *cp;

std::size_t sz = strlen(char_s);

const char* str_end1 = str_begin( char_s ) + sz;

for (cp = str_begin(char_s); cp != str_end(char_s); ++cp)

    cout << *cp;

I have couple of questions:

1. In the loop, boost::range seems to be calling strlen every iteration. This is an overhead. I was wondering if there's a way I can pass in the length myself so that boost::range would use it and avoid calling strlen().

2. If it's not possible, is there a way for me to use iterators (boost or non-boost) over char strings?

Thanks so much in advance for your help,
Anant

The information contained in this email message and its attachments is intended only for the private and confidential use of the recipient(s) named above, unless the sender expressly agrees otherwise. Transmission of email over the Internet is not a secure communications medium. If you are requesting or have requested the transmittal of personal data, as defined in applicable privacy laws by means of email or in an attachment to email, you must select a more secure alternate means of transmittal that supports your obligations to protect such personal data. If the reader of this message is not the intended recipient and/or you have received this email in error, you must take no action based on the information in this email and you are hereby notified that any dissemination, misuse or copying or disclosure of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by email and delete the original message.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net