有没有人已经看到基于std :: string的非可变String [英] Does anyone has already seen a non mutable String based on std::string

查看:65
本文介绍了有没有人已经看到基于std :: string的非可变String的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我目前正在实现从.NET到现代C ++的一些基本类。

我想知道是否有人会知道非可变字符串类。

Hi,

I am currently implementing some basic classes from .NET into modern C++.
And I would like to know if someone would know a non mutable string class.

推荐答案

Vincent RICHOMME发布:
Vincent RICHOMME posted:

Hi,

I am currently implementing some basic classes from .NET into modern
C++. And I would like to know if someone would know a non mutable
string class.



之前从未听过非变异类一词。

什么是非变异类?它是一个没有成员对象的类吗?
是可变的吗?

-Tomás


Never heard the term, "non-mutable class", before.
What''s a non-mutable class? Is it a class which has no member objects which
are mutable?
-Tomás


Tomásaécrit:
Tomás a écrit :
Vincent RICHOMME发布:
Vincent RICHOMME posted:


我目前正在实现从.NET到现代的一些基本类
C ++。而且我想知道是否有人会知道一个不可变的字符串类。
Hi,

I am currently implementing some basic classes from .NET into modern
C++. And I would like to know if someone would know a non mutable
string class.



之前从未听过非变异类一词。

什么是非变异类?它是一个没有成员对象的类吗?

-Tomás


Never heard the term, "non-mutable class", before.
What''s a non-mutable class? Is it a class which has no member objects which
are mutable?
-Tomás



非可变意味着一旦创建的对象无法修改。

对于字符串,这意味着一旦字符串被分配了

就无法修改它,或者如果你想修改它,修改就是

在副本上完成,而不是在字符串本身上完成。

实际上我在sourceforge上找到了一个实现并基于

提升,但我不喜欢提升依赖性。


non mutable means that once created object cannot be modidified.
In the case of string, it means that once the string has been allocated
it cannot be modified or if you want to modify it, the modification is
done on a copy and not on the string itself.
Actually I have found one implementation on sourceforge and based on
boost but I don''t like boost dependencies.


Vincent RICHOMME发布:

Vincent RICHOMME posted:

non mutable意味着一旦创建的对象无法修改。
non mutable means that once created object cannot be modidified.




#include< string>


int main()

{

std :: string const str(蚀刻在石头上。);

}

我错过了什么?

-Tomás



#include <string>

int main()
{
std::string const str("Etched in stone.");
}
Am I missing something?
-Tomás


这篇关于有没有人已经看到基于std :: string的非可变String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆