POS_TYPEとOFF_TYPEを特性を使用してINT64_Tにする方法はありますか?
-
12-10-2019 - |
質問
私は特徴が何であるかを理解しようとしています。たとえば、 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 -Egを含めるためだけにクラスを作成する必要があるという欠点があります。サードパーティのコンテナと基本タイプは、コードでは使用できません。 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