CMakeTutorialStep1 2.3.12
Loading...
Searching...
No Matches
ModernParadigm.hxx File Reference

现代 C++ 范式演示:强类型、std::expected、span、concept。 More...

#include <concepts>
#include <cstdint>
#include <expected>
#include <span>
#include <string_view>

Go to the source code of this file.

Classes

struct  tutorial::Price
 价格强类型(整型分),避免与 Quantity 静默混用 More...
struct  tutorial::Quantity
 数量强类型(整型单位) More...

Namespaces

namespace  tutorial

Concepts

concept  tutorial::NamedValue
 Concept 演示:具名数值类型须暴露 .value 且可转为 int32.

Enumerations

enum class  tutorial::ParseErr : int { tutorial::empty = 1 , tutorial::invalid = 2 , tutorial::overflow = 3 }
 价格字符串解析的可恢复错误码 More...

Functions

std::expected< Price, ParseErr > tutorial::parse_price_cents (std::string_view s)
 逐字符解析十进制整数分;空串、非数字或溢出返回对应 ParseErr
std::int64_t tutorial::sum_cents (std::span< const Price > prices) noexcept
 对价格数组求和(std::span 零拷贝 API)
template<NamedValue T>
constexpr std::int32_t tutorial::raw_qty (T t) noexcept
 提取 NamedValue 的原始数量值

Detailed Description

现代 C++ 范式演示:强类型、std::expected、span、concept。

供主程序、GTest、Benchmark 与 libFuzzer 共用;实现见 ModernParadigm.cxx。