不可变字符串vs std :: string [英] immutable strings vs std::string
问题描述
我最近一直在阅读关于不可变字符串的信息,此处和这里以及一些有关为什么D 选择了不可变字符串。似乎有很多优点。
- 简单的线程安全
- 更安全 $
-
-
-
- $ b
更多新的语言有不可变的字符串,D2.0,Java,C#,Python等。
C ++会从不可变字符串中受益吗? / p>
是否可以在c ++(或c ++ 0x)中实现具有所有这些优点的不可变字符串类?
更新:
不可变字符串有两种尝试 const_string 和 fix_str 。在过去的十年中,这两种方法都没有更新。它们是否被使用?为什么const_string不会加速?
解决方案作为意见:
- 是的,我非常喜欢C ++的不可变字符串库。
- 不,我不喜欢std :: string是不可变的。
真的值得做吗(作为标准库功能)?我会说不。 const的使用给了你本地不可变的字符串,系统编程语言的基本本质意味着你真的需要可变字符串。
I've recent been reading about immutable strings, here and here as well some stuff about why D chose immutable strings. There seem to be many advantages.
- trivially thread safe
- more secure
- more memory efficient in most use cases.
- cheap substrings (tokenizing and slicing)
Not to mention most new languages have immutable strings, D2.0, Java, C#, Python, etc.
Would C++ benefit from immutable strings?
Is it possible to implement an immutable string class in c++ (or c++0x) that would have all of these advantages?
update:
There are two attempts at immutable strings const_string and fix_str. Neither have been updated in half a decade. Are they even used? Why didn't const_string ever make it into boost?
解决方案As an opinion:
- Yes, I'd quite like an immutable string library for C++.
- No, I would not like std::string to be immutable.
Is it really worth doing (as a standard library feature)? I would say not. The use of const gives you locally immutable strings, and the basic nature of systems programming languages means that you really do need mutable strings.
这篇关于不可变字符串vs std :: string的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!