Frage

I'm currently facing a problem I haven't been able to solve myself. Basically what I'm trying to do is implement some linq-like behaviour in C++.

I'll start off with the code in my header:

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
}

And this is how I'd like it to be instantiated:

std::vector<int> my_vec;
queryable<std::vector<int> > q(my_vec);

Needless to say this doesn't work (otherwist I wouldn't be here :) )

Now the even stranger part is that even this doesn't seem to work:

std::vector<int> my_vec;
queryable<int, std::allocator, std::vector> q(my_vec);

As you can see (by looking at the select function), it is important to me to not just use something like this:

template<typename T> class queryable;

Any suggestions on how to solve this? And is this even possible?

Any help would be appreciated!

EDIT: the errors I'm getting:

../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

EDIT 2:

As far as I understand the compiler is complaining about C not taking 2 class arguments, but 1 class argument and 1 templated class argument (1), because I defined C to be that way. Is there any way to resolve this issue?

Keine korrekte Lösung

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top