我试图了解特征是什么,例如typedef typename traits_type::off_type off_type
GNU 实现中的表达式fstream
。
当我处理大于 2/4 GB 的文件时出现了这个问题。我发现使用适当的标志重新编译 STL 库通常可以解决大文件问题。
我试图了解特征是什么,例如typedef typename traits_type::off_type off_type
GNU 实现中的表达式fstream
。
当我处理大于 2/4 GB 的文件时出现了这个问题。我发现使用适当的标志重新编译 STL 库通常可以解决大文件问题。
特征是向现有类型“添加”属性的一种方式。假设我们正在创建一个容器类型,其中包含一个 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;
};
此外,特征模板可以是使用它的算法的参数,这允许我们使用具有单一数据类型的不同特征(参见std::string
类)。
也就是说,我认为特征与 64 位系统没有太大关系。