有没有一种方法可以使pos_type和off_type成为使用特征的INT64_T?
-
12-10-2019 - |
题
我试图理解哪些特征是什么,例如表达 typedef typename traits_type::off_type off_type
在GNU实施中 fstream
.
当我处理大于2/4 GB的文件时,这个问题出现了。我发现重新编译STL库,并带有适当的标志,通常可以解决大型文件问题。
解决方案
特征是将属性添加到现有类型的一种方式。假设我们正在创建一个容器类型,该类型包含一个键入的数据类型。经典的方式是:
template <class T>
struct Cont { typedef T contained_type; }
这是一个缺点,即我们必须创建班级才能包含Typedef-例如。第三方容器和基本类型不能由假设的代码使用 Cont::contained_type
类型。因此,我们引入了一个特征结构,该结构在此过程中增加了间接:
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;
};
ALOS,特征模板可以是使用它的算法的参数,这使我们能够使用单个数据类型使用不同的性状(请参阅 std::string
班级)。
也就是说,我认为特征与64位系统无关。
不隶属于 StackOverflow