私は現在、自分では解決できない問題に直面しています。基本的に私がやろうとしているのは、C++ で linq のような動作を実装することです。
ヘッダーのコードから始めます。
template<typename T, template<class = T> class A,
template<class = T, template<class=T> class = A> class C>
class queryable
{
public:
typedef T value_type;
typedef A<value_type> allocator_type;
typedef C<value_type, allocator_type> container_type; // (1)
typedef queryable<T, A, C> type;
queryable(container_type const &) { }
template<typename _Out> queryable<_Out, A, C> select(/* some delegate */);
// more methods etc
}
そして、これは私がそれをインスタンス化する方法です:
std::vector<int> my_vec;
queryable<std::vector<int> > q(my_vec);
言うまでもなく、これは機能しません(そうでなければ、私はここにいません:))
さらに奇妙なのは、これでも機能しないように見えることです。
std::vector<int> my_vec;
queryable<int, std::allocator, std::vector> q(my_vec);
ご覧のとおり (選択関数を見てください)、次のようなものだけを使用しないことが重要です。
template<typename T> class queryable;
これを解決する方法について何か提案はありますか? そして、これは可能ですか?
どんな助けでも大歓迎です!
編集:私が得ているエラー:
../entry.cpp:19:58: error: type/value mismatch at argument 3 in template parameter list for ‘template<class T, template<class> class A, template<class, template<class> class<template-parameter-2-2> > class C> class failproof::collections::queryable’
../entry.cpp:19:58: error: expected a template of type ‘template<class, template<class> class<template-parameter-2-2> > class C’, got ‘template<class _Tp, class _Alloc> class std::vector’
../entry.cpp:19:61: error: invalid type in declaration before ‘;’ token
編集2:
私が理解している限り、コンパイラーは、C が 2 つのクラス引数をとらず、1 つのクラス引数と 1 つのテンプレート化されたクラス引数 (1) をとらないことに不平を言っています。これは、C をそのように定義したためです。この問題を解決する方法はありますか?