UE学习日志#22 C++笔记#8 基础复习8 string和string_view2

1 std::string_view类

        string_view基本上就是const string&的简单替代品,但不会产生开销。他不复制字符串。

        string_view添加了remove_prefix(size_t)和remove_suffix(size_t)方法,前者将起始指针给定的偏移量来收缩字符串,后者则将结尾指针倒退给定的偏移量来收缩字符串。

    string_view.data();
    string{string_view};

        只能以这种方式接受const string&。

        返回字符串的函数应返回const std::string&或string,但不应返回string_view,有返回的string_view无效的风险,例如当它指向的字符串需要重新分配时。

1.1 永远不要使用string_view保存临时字符串的视图

1.2 同string的末尾加s,可用末尾加sv将字面量解释为std::string_view

2 字符串格式化

        format()的一般占位符:{},中间的格式[index][:specifiier],表示索引和格式说明符,省略索引和显示说明索引不能混用。

2.1 格式说明符

[[fill]align][sign][#][0][width][.precision][type]

1. width

        width指定待格式化的值所占字段的最小宽度,例如5.width也可以是另一组花括号,成为动态宽度。如果在花括号中指定了索引,例如{3},则动态宽度的width取自给定索引对应的format()的实参。如果未指定索引,例如{},则width取自format()的实参列表的下一个参数。

int i{42};
cout<<format("|{:5}|",i)<<endl;
cout<<format("|{:{}}|",i,7)<<endl;

2. [fill]align

        align表示对齐方式<表示左对齐,>表示右对齐,^表示居中对齐。[fill]表示指定长度未到时的填充字符。

3. sign

        -表示只显示负数的符号,+代表都显示,space代表对负数使用符号,对正数使用空格。

4. #

        在指定格式前插入前缀来表示格式

5.type

        指定了给定值要被格式化的类型。

6. precision

        指定字符串或浮点的精度。

7.0

        指定了对齐则忽略此项,否则在前缀之后,数值的前面填充0.

2.2(待补充)支持自定义类型

### UE_BUILD_SHIPPING Macro Definition and Configuration In Unreal Engine, `UE_BUILD_SHIPPING` is a preprocessor macro used primarily during the build process when compiling code intended for final product releases. When this macro is defined, it indicates that the engine should compile with optimizations specific to shipping builds while excluding debug information or development-specific functionalities. The inclusion of `UE_BUILD_SHIPPING` ensures that only necessary components are included in the executable, leading to better performance and smaller file sizes suitable for end-user distribution[^1]. To configure projects using `UE_BUILD_SHIPPING`, developers typically adjust settings within `.ini` files such as `DefaultEngine.ini`. For instance, certain features like Distance Field Global Illumination require explicit enabling through console variables set in `ConsoleVariables.ini` alongside ensuring relevant renderer project configurations support these advanced graphical options. Additionally, transitioning towards newer formats for representing mesh assets enhances compatibility and introduces improved workflows over time[^2], although directly related changes might not involve `UE_BUILD_SHIPPING`. For practical demonstration purposes on how to apply `UE_BUILD_SHIPPING`, consider modifying C++ source files where conditional compilation directives check whether `UE_BUILD_SHIPPING` has been defined before including particular pieces of code: ```cpp #if UE_BUILD_SHIPPING // Code block executed exclusively under SHIPPING configuration. #endif ``` --related questions-- 1. How does defining `UE_BUILD_SHIPPING` impact game performance? 2. What other macros exist besides `UE_BUILD_SHIPPING` for different build types? 3. Can custom modules be excluded from shipping builds via `UE_BUILD_SHIPPING`? 4. In what scenarios would one disable features specifically for non-shipping configurations?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值