gpt4 book ai didi

c++ - 有没有办法使用特征使 pos_type 和 off_type 成为 int64_t?

转载 作者:行者123 更新时间:2023-11-28 08:24:00 32 4
gpt4 key购买 nike

我试图了解什么是特征,例如 fstream 的 GNU 实现中的 typedef typename traits_type::off_type off_type 等表达式。

当我处理大于 2/4 GB 的文件时出现了这个问题。我发现使用适当的标志重新编译 STL 库通常可以解决大文件问题。

最佳答案

Traits 是一种向现有类型“添加”属性的方法。假设我们正在创建一个容器类型,它包含一个 typedef 来告诉它包含的数据类型。经典的方式是:

template <class T>
struct Cont { typedef T contained_type; }

这样做的缺点是我们必须创建我们的类来包含 typedef - 例如。假定 Cont::contained_type 类型的代码不能使用第三方容器和基本类型。所以我们引入一个traits struct,在这个过程中增加了一个间接:

template <class C>
struct container_traits; // this struct would contain the contained_type for container C

template <class T>
struct Cont { ... } // no typedef here

template <class T>
struct container_traits<Cont<T> >
{
typedef T contained_type; // by this, we say that the contained_type of Cont<T> is T
};

template <class T, unsigned N>
struct container_traits<T[N]>
{
// this is the advantage of traits - we can add information for arrays, which can have no member typedefs
typedef T contained_type;
};

另外,traits 模板可以作为使用它的算法的参数,这允许我们对单一数据类型使用不同的 traits(参见 std::string 类)。

也就是说,我认为特征与 64 位系统没有太大关系。

关于c++ - 有没有办法使用特征使 pos_type 和 off_type 成为 int64_t?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4719382/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com