0

typedef typename traits_type::off_type off_typeたとえば、のGNU実装のような式など、特性が何であるかを理解しようとしていfstreamます。

この質問は、2/4GBを超えるファイルを操作しているときに出てきました。STLライブラリを適切なフラグを使用して再コンパイルすると、通常、大きなファイルの問題が解決されることがわかりました。

4

1 に答える 1

1

特性は、既存の型にプロパティを「追加」する方法です。含まれているデータ型を伝える typedef を含むコンテナー型を作成しているとしましょう。古典的な方法は次のようになります。

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

これには、typedef を含めるためだけにクラスを作成する必要があるという欠点があります。サード パーティのコンテナーと基本型は、型を想定するコードでは使用できませんCont::contained_type。そのため、プロセスに間接性を追加する traits 構造体を導入します。

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 ビット システムとあまり関係があるとは思えません。

于 2011-01-18T01:17:17.530 に答える