ここでテンプレート化されたクラスを呼び出すにはどうすればよいですか
テンプレート パラメーターTBackBufferType、TFrontBufferTypeを持つ FrontBackBuffer
template< typename TBufferTypeFront, typename TBufferTypeBack = TBufferTypeFront>
class FrontBackBuffer{
public:
explicit FrontBackBuffer(
TBufferTypeFront const & m_front,
TBufferTypeBack const & m_back):
m_Front(m_front),
m_Back(m_back)
{
};
~FrontBackBuffer()
{};
typename std::remove_reference<
typename std::remove_pointer<TBufferTypeFront>::type
>::type & getFront(){return m_Front;} // error: invalid initialization of reference of type 'A&' from expression of type 'A*'| (here T is A)
typename std::remove_reference<
typename std::remove_pointer<TBufferTypeBack>::type
>::type & getBack(){return m_Back;}
TBufferTypeFront m_Front; ///< The front buffer
TBufferTypeBack m_Back; ///< The back buffer
};
私は次のことを達成したいと思います:
コード内で一貫性を保つために、バッファー内の Type が何であれ、常にバッファーへの参照を返す関数getFront/Backを使用することをお勧めします (const または non-const のいずれかによって異なります)。 type: eg const int = T should return a const int & reference! このようなコードを書きたいと思います
FrontBuffer<const int&, std::vector<int> > a; a.getFront() = 4 //COmpile error! OK!; a.getBack()[0] = 4; FrontBuffer< int*, GAGAType * > b; b.getBack() = GAGAType(); b.getFront() = int(4); // this is no ERROR, i would like to get the reference of the memory location pointet by int* ....
バッファーの型を参照からポインター (逆参照する必要がある場所) に変更した場合に構文の変更を避けたいので、これが必要です。
このような Buffer クラスは、可能なすべてのタイプ (shared_ptr など) で受け入れることができますか? asd
私が欲しいのはアクセスだけで、非常にパフォーマンスが高く、コピーなどはありません。
この汎用バッファの書き方が本当にわかりませんか? 誰かが手がかりを持っていますか?
ありがとう!!!
EDIT1逆参照されたポインターに割り当てることもできるようにしたい:
b.getFront() = int(4); // this is no ERROR, i would like to get the reference of the memory location pointet by int* ....
それが私の特性に関する問題の出番です!