473,508 Members | 2,331 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple calls on same std::string object

Hello All,

Is the following fragment well defined?

std::string some_str("Hello World");
....
some_str.replace(some_str.find("Wor"), strlen("Wor"), other_str);

Or does the nested call on the same string object invoke UB?

Regards,
Suman

Apr 10 '07 #1
3 1193
* Suman:
Hello All,

Is the following fragment well defined?

std::string some_str("Hello World");
...
some_str.replace(some_str.find("Wor"), strlen("Wor"), other_str);

Or does the nested call on the same string object invoke UB?
Arguments are evaluated before a function is called.

So, no UB on that account.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Apr 10 '07 #2
On Tue, 10 Apr 2007 14:54:32 +0300, Suman <sk*****@gmail.comwrote:
Hello All,

Is the following fragment well defined?

std::string some_str("Hello World");
...
some_str.replace(some_str.find("Wor"), strlen("Wor"), other_str);

Or does the nested call on the same string object invoke UB?
Why should it? The nested call returns before replace() is called?

Boris
Apr 10 '07 #3
On Apr 10, 5:08 pm, Boris <b...@gtemail.netwrote:
On Tue, 10 Apr 2007 14:54:32 +0300, Suman <skar...@gmail.comwrote:
....
...
some_str.replace(some_str.find("Wor"), strlen("Wor"), other_str);
Or does the nested call on the same string object invoke UB?

Why should it? The nested call returns before replace() is called?
I forgot about the 'argument evaluation before call' part.
Thank you all for your express responses.

Regards,
Suman
Apr 10 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
22702
by: Espen Ruud Schultz | last post by:
Lets say I have a char pointer and an std::string. Is it possible to get a pointer to the std::string's "content" so that the char pointer can point to the same text? And vice versa; can I give...
2
2892
by: Cheng Mo | last post by:
Below code cannot be compiled. try { throw std::string; } catch(...) { } While below is correct.
10
9034
by: lovecreatesbea... | last post by:
Is it correct and safe to compare a string object with "", a pair of quotation marks quoted empty string?If the string object: s = ""; does s contain a single '\'? Is it better to use...
1
1417
by: mathieu | last post by:
Hi C++ gurus, Why in the following code the std::string destructor is being called before the 'catch' ? Thanks, -Mathieu #include <iostream> #include <sstream>
0
7229
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7129
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5637
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1566
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
428
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.